马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我用过requests.get函数得到了一个网页的html代码,import requests
import urllib.request
import json
import re,random
USER_AGENT_LIST = [
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5',
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
'MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
'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.3870.400 QQBrowser/10.8.4405.400'
]
ua = random.choice(USER_AGENT_LIST)
head = {'User-Agent': ua }
url = 'https://xyq-m.cbg.163.com/cgi/mweb/pl'
shuxing = {"search_type":"overall_role_search","order_by":"selling_timeDESC"}
res = requests.get(url,headers = head,params = shuxing)
html = res.text
但是我想爬的内容HTML里面没有,而是在浏览器中的审查元素-网络-中的XHR文件中显示出来了,是jQuery开头的,说是需要正则解析,请大佬应该怎么解析啊
看看是不是这样:
import requests
import re
url = 'https://xyq-m.cbg.163.com/cgi-bin/recommend.py?callback=jQuery33109536810016282733_1626832033577&act=recommd_by_role&client_type=embed&count=15&search_type=query&order_by=&page=1&_=1626832033578'
data = requests.get(url)
data.encoding = 'unicode_escape'
result = re.search('{.+}',data.text)
print(result.group())
|