Chat with us, powered by LiveChat Scraping Numbers from HTML using BeautifulSoup In this assignment you will write a Python program similar - Writeedu

Scraping Numbers from HTML using BeautifulSoup In this assignment you will write a Python program similar

Scraping Numbers from HTML using BeautifulSoup In this assignment you will write a Python program similar to http://www.py4e.com/code3/urllink2.py. The program will use urllib to read the HTML from the data files below, and parse the data, extracting numbers and compute the sum of the numbers in the file. 

We provide two files for this assignment.  One is a sample file where we give you the sum for your testing and the other is the actual data you need to process for the assignment. 

You do not need to save these files to your folder since your program will read the data directly from the URL. Note: Each student will have a distinct data url for the assignment – so only use your own data url for analysis. 

Data Format 

The file is a table of names and comment counts.   You can ignore most of the data in the file except for lines like the following: 

<tr><td>Modu</td><td><span class="comments">90</span></td></tr>
<tr><td>Kenzie</td><td><span class="comments">88</span></td></tr>
<tr><td>Hubert</td><td><span class="comments">87</span></td></tr>

You are to find all the <span> tags in the file and pull out the numbers from the tag and sum the numbers. 

Look at the sample code provided.  It shows how to find all of a certain kind of tag, loop through the tags and extract the various aspects of the tags. 

...
# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
  # Look at the parts of a tag
  print 'TAG:',tag
  print 'URL:',tag.get('href', None)
  print 'Contents:',tag.contents[0]
  print 'Attrs:',tag.attrs

You need to adjust this code to look for span tags and pull out the text content of the span tag, convert them to integers and add them up to complete the assignment. 

Sample Execution 

$ python3 solution.py
Enter - http://py4e-data.dr-chuck.net/comments_42.html
Count 50
Sum 2...

Turning in the Assignment 

Enter the sum from the actual data and your Python code below:
Sum:  (ends with 25)
Python code:

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteEdu. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

Do you need help with this question?

Get assignment help from WriteEdu.com Paper Writing Website and forget about your problems.

WriteEdu provides custom & cheap essay writing 100% original, plagiarism free essays, assignments & dissertations.

With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.

Chat with us today! We are always waiting to answer all your questions.

Click here to Place your Order Now