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
|
import requests,time,random
import pandas as pd
proxies={'http': 'http://127.0.0.1:8889', 'https': 'http://127.0.0.1:8889'}
cookies = {
'wzws_sessionid': 'gDIyMi4yNDQuMTIzLjE3OIJkYjFjYWGBM2MwZWZmoGT2+fU=',
'htVC_2132_saltkey': 'UW6PnZBb',
'htVC_2132_lastvisit': '1693902481',
'htVC_2132_lastact': '1693902666%09forum.php%09forumdisplay',
'htVC_2132_st_t': '0%7C1693902666%7C8e0f8128b4a9faa43733ba3af60b3420',
'htVC_2132_forum_lastvisit': 'D_16_1693901860D_2_1693902666',
'htVC_2132_visitedfid': '2D16',
}
headers = {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9,en-CN;q=0.8,en;q=0.7,zh-HK;q=0.6',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'DNT': '1',
'Pragma': 'no-cache',
'Referer': 'https://www.52pojie.cn/forum-2-1.html',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="102"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
def get_tiewen(page):
params = (
('mod', 'forumdisplay'),
('fid', '2'),
('page', str(page)),
('typeid', '4'),
('t', str(random.randint(189047396,999999999))),
)
response = requests.get('https://www.52pojie.cn/forum.php', headers=headers, params=params, cookies=cookies,proxies=proxies, verify=False)
return response.text
# 获取第二页,然后在此基础上拼接
html = get_tiewen(2)
df = pd.read_html(html)[3]
for page in range(3,234):
html = get_tiewen(page)
try:
df = pd.concat([df,pd.read_html(html)[3]]) # 合并df
except:
print(page)
time.sleep(random.randint(1,3))
df.to_csv("52.csv",index=False)
|