-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortl.py
59 lines (49 loc) · 1.72 KB
/
sortl.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
from spiderA import SpiderHTML
from getUrl import SearchUrl
from collections import Counter
from bs4 import BeautifulSoup
import requests
import os
# 目标url
# url = 'https://movie.douban.com/subject/26683290/'
class SortList(object):
def __init__(self, searchName):
self.searchName = searchName
def start(self):
ss = SearchUrl(self.searchName)
url = ss.start()
class doubanDetil(SpiderHTML):
def __init__(self, url):
self.url = url
def start(self):
# print(url)
# print(self.url)
soup = self.getUrl(self.url)
titles = soup.select('.recommendations-bd dt a')
findUrls = [x['href'] for x in titles]
aboutImg = soup.select('.recommendations-bd dt a img')
imgNames = [x['alt'] for x in aboutImg]
imgURLs = [x['src'] for x in aboutImg]
# print(findUrl,imgName,imgURL)
chapterInfo = []
for imgName, imgURL, findUrl in zip(imgNames, imgURLs, findUrls):
listof = {
'name': imgName,
'img': imgURL,
'url': findUrl
}
chapterInfo.append(listof)
return chapterInfo
spider = doubanDetil(url)
f = spider.start()
allM = []
for x in f:
# print('---------' + x['name'])
subspider = doubanDetil(x['url'])
ff = subspider.start()
# print(ff)
for y in ff:
allM.append(y['name'])
c = Counter(allM)
sss = c.most_common(1000)
return sss