import requests
import json
import time
pagesize=300
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36',
}
posturl = "https://m.ctrip.com/restapi/soa2/13444/json/getCommentCollapseList?_fxpcqlniredt=09031099112624127484"
def getdata():
j = 1
for i in range(1,pagesize):
request = {
'arg': {'channelType': '2',
'collapseType': '0',
'commentTagId': '0',
'pageIndex': str(i),
'pageSize': '10',
'poiId': '75916',
'sortType': '3',
'sourceType': '1',
'starType': '0'},
'head': {'auth': "",
'cid': "09031099112624127484",
'ctok': "",
'cver': "1.0",
'extension': [],
'lang': "01",
'sid': "8888",
'syscode': "09",
'xsid': ""}
}
time.sleep(3)
html = requests.post(posturl, data=json.dumps(request), headers=headers)
html1 = json.loads(html.text)
print('正在爬取第'+str(i)+'页')
items = html1['result']['items']
#保存文件
with open("xiecheng.csv", "a", newline='', encoding='GB18030') as f:
for k in items:
f.write(str(k['commentId']))
f.write("\t")
f.write(k['content'])
f.write("\n")
j += 1
if __name__ == '__main__':
getdata()
python爬取携程评论
最新推荐文章于 2026-05-19 09:04:00 发布
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
您可能感兴趣的与本文相关的镜像
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

9341

被折叠的 条评论
为什么被折叠?



