-
Notifications
You must be signed in to change notification settings - Fork 1
/
scanner.py
80 lines (63 loc) · 2.31 KB
/
scanner.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import requests
import os
import bs4
import urllib2
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def download(link,target):
imagefile = urllib2.urlopen(link)
with open(target,'wb') as output:
output.write(imagefile.read())
if not os.path.isdir("./images"):
os.mkdir("./images")
if not os.path.isdir("./images/females"):
os.mkdir("./images/females")
if not os.path.isdir("./images/males"):
os.mkdir("./images/males")
base = "http://www.imdb.com"
images = 103
for start in xrange(201,4000,100):
url = base + '/search/name?gender=female&count=100&start='+str(start)
r = requests.get(url)
html = r.text
soup = bs4.BeautifulSoup(html, 'html.parser')
for img in soup.select('.detailed .image'):
link = img.find('a').get('href')
print "opening " + str(images) + (base + link)
r = requests.get(base + link)
html = r.text
soup = bs4.BeautifulSoup(html,'html.parser')
selector = soup.find('time')
if selector == None:
continue
date = selector.get('datetime')
selector = soup.find('img',{"id":"name-poster"})
if selector == None:
continue
image = selector.get('src')
images = images + 1
download(image,"./images/females/"+str(images)+"+"+date+".jpg")
print "downloaded"
for start in xrange(1,4000,100):
url = base + '/search/name?gender=male&count=100&start='+str(start)
r = requests.get(url)
html = r.text
soup = bs4.BeautifulSoup(html, 'html.parser')
for img in soup.select('.detailed .image'):
link = img.find('a').get('href')
print "opening " + str(images) + (base + link)
r = requests.get(base + link)
html = r.text
soup = bs4.BeautifulSoup(html,'html.parser')
selector = soup.find('time')
if selector == None:
continue
date = selector.get('datetime')
selector = soup.find('img',{"id":"name-poster"})
if selector == None:
continue
image = selector.get('src')
images = images + 1
download(image,"./images/males/"+str(images)+"+"+date+".jpg")
print "downloaded"