diff --git a/Assignments/Assignment_13.1 b/Assignments/Assignment_13.1 new file mode 100644 index 0000000..a62050d --- /dev/null +++ b/Assignments/Assignment_13.1 @@ -0,0 +1,37 @@ +Scraping Numbers from HTML using BeautifulSoup In this assignment you will write a Python program similar to http://www.pythonlearn.com/code/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. +Sample data: http://python-data.dr-chuck.net/comments_42.html (Sum=2553) +Actual data: http://python-data.dr-chuck.net/comments_242237.html (Sum ends with 67) + +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: +Modu90 +Kenzie88 +Hubert87 + + +You are to find all the 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 +$ python solution.py +Enter - http://python-data.dr-chuck.net/comments_42.html +Count 50 +Sum 2482 + + +Turning in the Assignment +Enter the sum from the actual data and your Python code below: +Sum: (ends with 67) \ No newline at end of file diff --git a/Assignments/Assignment_13.2 b/Assignments/Assignment_13.2 new file mode 100644 index 0000000..67f2ef5 --- /dev/null +++ b/Assignments/Assignment_13.2 @@ -0,0 +1,31 @@ +Following Links in Python +In this assignment you will write a Python program that expands on http://www.pythonlearn.com/code/urllinks.py. The program will use urllib to read the HTML from the data files below, extract the href= vaues from the anchor tags, scan for a tag that is in a particular position relative to the first name in the list, follow that link and repeat the process a number of times and report the last name you find. +We provide two files for this assignment. One is a sample file where we give you the name for your testing and the other is the actual data you need to process for the assignment +Sample problem: Start at http://python-data.dr-chuck.net/known_by_Fikret.html +Find the link at position 3 (the first name is 1). Follow that link. Repeat this process 4 times. The answer is the last name that you retrieve. +Sequence of names: Fikret Montgomery Mhairade Butchi Anayah +Last name in sequence: Anayah + +Actual problem: Start at: http://python-data.dr-chuck.net/known_by_Ross.html +Find the link at position 18 (the first name is 1). Follow that link. Repeat this process 7 times. The answer is the last name that you retrieve. +Hint: The first character of the name of the last page that you will load is: S + +Strategy +The web pages tweak the height between the links and hide the page after a few seconds to make it difficult for you to do the assignment without writing a Python program. But frankly with a little effort and patience you can overcome these attempts to make it a little harder to complete the assignment without writing a Python program. But that is not the point. The point is to write a clever Python program to solve the program. +Sample execution +Here is a sample execution of a solution: +$ python solution.py +Enter URL: http://python-data.dr-chuck.net/known_by_Fikret.html +Enter count: 4 +Enter position: 3 +Retrieving: http://python-data.dr-chuck.net/known_by_Fikret.html +Retrieving: http://python-data.dr-chuck.net/known_by_Montgomery.html +Retrieving: http://python-data.dr-chuck.net/known_by_Mhairade.html +Retrieving: http://python-data.dr-chuck.net/known_by_Butchi.html +Retrieving: http://python-data.dr-chuck.net/known_by_Anayah.html + + +The answer to the assignment for this execution is "Anayah". +Turning in the Assignment +Enter the last name retrieved and your Python code below: +Name: (name starts with S) \ No newline at end of file diff --git a/Slides/05-02-16-Regex.pdf b/Slides/05-10-16-Regex.pdf similarity index 100% rename from Slides/05-02-16-Regex.pdf rename to Slides/05-10-16-Regex.pdf diff --git a/Slides/05-04-16-HTTP.pdf b/Slides/05-12-17-16-HTTP.pdf similarity index 100% rename from Slides/05-04-16-HTTP.pdf rename to Slides/05-12-17-16-HTTP.pdf diff --git a/Slides/05-19-16-WebServices.pdf b/Slides/05-19-16-WebServices.pdf new file mode 100644 index 0000000..3e23fb6 Binary files /dev/null and b/Slides/05-19-16-WebServices.pdf differ diff --git a/Slides/05-26-16-Objects.pdf b/Slides/05-26-16-Objects.pdf new file mode 100644 index 0000000..1b6106a Binary files /dev/null and b/Slides/05-26-16-Objects.pdf differ