-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
37 lines (32 loc) · 842 Bytes
/
parser.py
File metadata and controls
37 lines (32 loc) · 842 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
28
29
30
31
32
33
34
35
36
37
from bs4 import BeautifulSoup
import urllib.request as ur
import random
#import downloader
def get_html(url):
response = ur.urlopen(url)
return response.read()
def parse_top(html):
soup = BeautifulSoup(html, "lxml")
top250 = []
for i in range(1, 251):
row = soup.find('tr', id="top250_place_%d" %i)
name = row.find('a', class_="all")
top250.append(name.text)
return top250
def get_movie_name():
top250 = []
try:
f = open ('top250.txt', 'r')
except IOError as e:
print(u'Downloading top movies...')
top250 = parse_top(get_html('file:///home/konstantin-mint17/top250.html'))
f = open('top250.txt', 'w')
for i in range (0, 250):
f.write(top250[i] + '\n')
f.close()
f = open('top250.txt', 'r')
movie = f.readlines()[random.randint(0, 250)]
f.close()
return movie
if __name__ == '__main__':
main()