-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
54 lines (46 loc) · 1.43 KB
/
Copy pathparser.py
File metadata and controls
54 lines (46 loc) · 1.43 KB
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
from bs4 import BeautifulSoup
class LofterParser():
"""
解析Lofter页面,获取接下来应爬取的url与应爬取图片的url
"""
@classmethod
def getImgPageHref(cls,response):
"""
获取图片应有的连接-一个主贴中
"""
html = response.text
soup = BeautifulSoup(html,'lxml')
pageHrefs = []
for col in soup.select('.photo .img'):
try:
pageHrefs.append(col.select('a')[0]['href'])
except Exception as e:
print('Not a PhotoPage')
return pageHrefs
# TODO 用decorator加入打印日志功能?
@classmethod
def getImgHref(cls,response):
"""
获取高清图片地址
"""
html = response.text
soup = BeautifulSoup(html,'lxml')
imgHrefs = []
for post in soup.select('.img'):
if post.select('.imgclasstag'):
imgHrefs.append(post.select('.imgclasstag')[0]['bigimgsrc'])
return imgHrefs
@classmethod
def getUserpageHref(cls,response):
"""
获取点赞人的主页超链接
"""
html = response.text
soup = BeautifulSoup(html,'lxml')
userHrefs = []
for note in soup.select('.note.share'):
userHrefs.append(note.select('a')[0]['href'])
return userHrefs
# def main():
# if __name__ == '__main__':
# main()