-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_info2.py
executable file
·73 lines (64 loc) · 2.81 KB
/
get_info2.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
import requests
import time
from lxml import etree
class HanJuInfo():
def __init__(self, url):
self.headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3641.400 QQBrowser/10.4.3284.400'}
self.url = url
# 首页获取页面链接
def Get_Html(self):
response = requests.get(url=self.url, headers=self.headers)
if response.status_code == 200:
html = response.text
return html
# 页面解析出详情页的url
def Paser_Html(self):
content = self.Get_Html()
selector = etree.HTML(content)
print(selector)
print(content)
items = selector.xpath('//div[@class="js-navigation-container js-active-navigation-container"]/ul[@class="list g-clear"]/li[@class="item"]')
print(items)
for item in items:
self.info_url = item.xpath('./a/@href')[0]
self.info_urls = 'https://www.360kan.com' + self.info_url
# 解析详情页信息
response = requests.get(url=self.info_urls, headers=self.headers)
print("This is test")
with open('info.txt', 'a', encoding='utf-8') as f:
f.write("This is test")
f.write(response)
if response.status_code == 200:
selector = etree.HTML(response.text)
name = selector.xpath('//div[@class="title-left g-clear"]/h1/text()')[0]
time = selector.xpath('//*[@id="js-desc-switch"]/div[1]/p[2]/text()')[0]
place = selector.xpath('//*[@id="js-desc-switch"]/div[1]/p[3]/text()')[0]
actors = ''.join(selector.xpath('//*[@id="js-desc-switch"]/div[1]/p[6]//a//text()'))
detials = selector.xpath('//*[@id="js-desc-switch"]/div[3]/p/text()')[0]
yield {
'片面': name,
'时间': time,
'地区': place,
'主演': actors,
'简介': detials
}
info = {
'片面': name,
'时间': time,
'地区': place,
'主演': actors,
'简介': detials
}
self.save_info(str(info))
def save_info(self, content):
with open('info.txt', 'a', encoding='utf-8')as f:
f.write(content + '\n')
if __name__ == '__main__':
for x in range(1, 2):
url = 'https://github.com/ansible-collections/azure/issues'
han = HanJuInfo(url)
time.sleep(1)
print('第%s页' % x)
for i, x in enumerate(han.Paser_Html()):
print(i, x)