爬虫
-
打开携程网,找到某个景区点击跳转到详情页面。
-
按 F12 打开开发者工具,然后点击下评论下一页来监听是否有网络请求更新。如果没有那就看页面地址栏是否发生变化,前者是动态更新(post 请求,通过调后端接口完成数据更新),后者是静态更新(get 请求,通过 html 页面更新数据)。
通过搜索评论内容定位到评论数据是通过调 getCommentCollapseList 接口返回的。
- 那么我们现在已经知道数据在哪个接口中,接下来就需要在本地模拟调用这个请求即可,这里我是用 Python 的 requests 库实现。可使用 curlconverter.com 将 curl 请求转换为代码。
import requests
def crawlComment():
cookies = {
'GUID': '09031069217559688465',
'MKT_CKID': '1751274744072.9fx30.ncpi',
'_RSG': 'Ce4EW5dni37P3spnPcTGtA',
'_RDG': '281fac73a494fd20293dac96d16828aefe',
'_RGUID': '70ecc671-6038-4a0c-add0-766671cf60d9',
'_ga': 'GA1.1.1991158589.1751274745',
'nfes_isSupportWebP': '1',
'ibulocale': 'zh_cn',
'cookiePricesDisplayed': 'CNY',
'_abtest_userid': '1a3ec536-4b47-4de6-a67e-b8a48f5801d2',
'Corp_ResLang': 'zh-cn',
'_bfaStatusPVSend': '1',
'UBT_VID': '1752483344037.225tvy',
'_bfaStatus': 'success',
'_RF1': '123.177.53.139',
'intl_ht1': 'h4=2_77366892,1_125617009,1_1452207,1_37887757,1_1216725,1_451914',
'Session': ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
:
}
headers = {
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
:
}
params = {
: ,
:
}
json_data = {
: {
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
:
},
: {
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: ,
: []
}
}
response = requests.post(
,
params=params,
cookies=cookies,
headers=headers,
json=json_data
)
response.json()


