-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscrape_a_few_pages.py
More file actions
27 lines (24 loc) · 852 Bytes
/
scrape_a_few_pages.py
File metadata and controls
27 lines (24 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from urllib.request import urlopen
from bs4 import BeautifulSoup
link_list = ['/wiki/A_Few_Good_Men',
'/wiki/Apollo_13_(film)',
'/wiki/Mystic_River_(film)',
'/wiki/Fox_Broadcasting_Company',
'/wiki/The_Following',
'/wiki/Golden_Globe_Award',
'/wiki/Screen_Actors_Guild_Awards',
'/wiki/Primetime_Emmy_Award',
'/wiki/The_Guardian']
def getInfo(pageUrl):
html = urlopen('https://en.wikipedia.org' + pageUrl)
bs = BeautifulSoup(html, 'html.parser')
try:
print(bs.h1.get_text())
print(bs.find(id ='mw-content-text').find_all('p')[0])
print(bs.find(id='ca-edit').find('span').find('a').attrs['href'])
print('------------')
except AttributeError:
print('This page is missing something! No worries though!')
# call the function
for link in link_list:
getInfo(link)