Skip to content
Prev Previous commit
Lab 6
  • Loading branch information
wsimoneau committed Aug 19, 2016
commit e41b92a7ef1432c6cdbfdda775bb5ad71ba26a58
16 changes: 7 additions & 9 deletions Day4/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
import random
import time
import os
import re

#from nltk.util import clean_html
#import urllib2


# Open a web page
web_address='https://polisci.wustl.edu/faculty/specialization'
Expand All @@ -29,8 +24,7 @@


# Get the attributes
my_a_tag=soup.find_all('a')[2]
re.sub(r'<[^>]+>', '', str(my_a_tag)) #remove tags
my_a_tag=soup.find_all('a')[2] #?? What is the second index for
my_a_tag.attrs #Gives a dictionary with the attributes
my_a_tag.attrs.keys()
my_a_tag['alt']
Expand All @@ -42,8 +36,6 @@
mysection=soup.find_all('div')[0]
mysection.a #Gives the 'a' tag within the 'div' tag
mysection.find_all('a') #Gives the list of all 'a' tags within the 'div' tag
mysection.get_text()


# Creating a tree of objects

Expand Down Expand Up @@ -85,3 +77,9 @@ def download_page(address,path,filename,wait=5):
soup.prettify()


with open('scrapetest1.csv', 'wb') as f:
my_writer = csv.writer(f)
for i in mysection:
my_writer.writerow([i, i-1])


36 changes: 36 additions & 0 deletions Day6/lab6.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
#Exercise 1
#Write a function to calculate the greatest common divisor of two numbers

def common_divisor(number1, number2):
if number1 % number2 == 0:
print number2
elif number2 % number1 == 0:
print number1
return common_divisor(number2,(number1 % number2))






























#Exercise 2
#Write a function that returns prime numbers less than 121
Expand Down