关于动态爬取json格式文件
-
请问朋友们知道为什么打印text显示jQuery,里面的data为null?
我跟着视频做的博主data里面都是字典表内容,这个是我的import requests headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'} for i in range(1,2): param = { 'cb': ' jQuery112408933494064226006_1636169759698', 'pn': f' {i}', 'pz': ' 20', 'po': ' 1', 'np': ' 1', 'ut': ' bd1d9ddb04089700cf9c27f6f7426281', 'fltt': ' 2', 'invt': ' 2', 'fid': ' f3', 'fs': ' m:0 t:80', 'fields': ' f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152', '_': '1636169759852' } url = "http://49.push2.eastmoney.com/api/qt/clist/get" r = requests.get(url, params=param, headers=headers) print(r.text)
不知道哪里有问题?求解答。网址为“东方财富网” -
@96jennifer 原因找到了
因为param中批量加入引号,引号与内容有空格,
更新代码import requests headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'} for i in range(1,55): param = { 'cb': 'jQuery112408933494064226006_1636169759698', 'pn': f'{i}', 'pz': '20', 'po': '1', 'np': '1', 'ut': 'bd1d9ddb04089700cf9c27f6f7426281', 'fltt': '2', 'invt': '2', 'fid': 'f3', 'fs': 'm:0 t:80', 'fields': 'f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152', '_': '1636169759852' } url = "http://90.push2.eastmoney.com/api/qt/clist/get" r = requests.get(url, params=param, headers=headers) print(r.text)