当前位置:首页 > Web开发 > 正文

前一个的keyword不变

2024-03-31 Web开发

之前爬取总是呈现如图的功效:手动打开url显示的是想要的功效,但是爬取的时候data为空

技术图片

测验考试了多种要领,偶然得到了想要的功效:

技术图片

技术图片

这是多次尝试中告成与弗成功功效中结构的url

发明

技术图片

1)得到想要功效,所结构的url中keyword=******与下一参数间没有&链接

2)同样的keyword=%E8%A1%97%E6%8B%8D,参用差此外方法:‘https://www.toutiao.com/api/search/content/?keyword=%E8%A1%97%E6%8B%8D’+urlencode(params)

               requests.get(‘https://www.toutiao.com/api/search/content/?’,,params=params)

得到的url功效是不一样的,前一个的keyword不乱,还是%E8%A1%97%E6%8B%8D,后一种方法得到的keyword酿成了%25E8%25A1%2597%25E6%258B%258D

因为不是科班专业,仅仅按照本身所学的对照浅薄的常识连蒙带猜得出来的功效,还但愿有专业人士解释一下,嘻嘻。

附上部分代码

import requests from urllib.parse import urlencode def get_page(offset): params={ aid:24, app_name:web_search, format:json, offset:offset, autoload:true, count:20, en_qc:1, cur_tab:1, from:search_tab, pd:synthesis } headers={ X-Requested-With:XMLHttpRequest, Cookies:tt_webid=6788393831844185614; WEATHER_CITY=%E5%8C%97%E4%BA%AC; tt_webid=6788393831844185614; csrftoken=0fd39b0f026752a8f38a902ab9226d44; s_v_web_id=k64mh7pe_9IueD6zl_X1iG_4smt_8Dkd_SMrb5NXXMR8G; __tasessionId=naf9b8ylp1580623604878, Host:, Referer:https://www.toutiao.com/search/?keyword=%E8%A1%97%E6%8B%8D, User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 } try: url=https://www.toutiao.com/api/search/content/?keyword=%E8%A1%97%E6%8B%8D+urlencode(params) response=requests.get(url,headers=headers) response.raise_for_status response.encoding=response.apparent_encoding print(response.url) return response.json() except: print(爬取堕落)

ajax爬取今日头条街拍图片——data呈现none的解决

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30681.html