|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我刚才试了,结果直接返回的链接失效,把请求头全部都加上了,还是不行,大佬们,百度加入了什么可怕的反爬虫逻辑,我的代码如下:
import bs4
import requests
header = {
'Host':'image.baidu.com',
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Upgrade-Insecure-Requests':'1',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0;win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/siqned-exchange;v=b3;q=0.9'}
def request(url, encode):
r = requests.get(url)
r.encoding = encode
print(r.text)
soup = bs4.BeautifulSoup(r.text, 'html.parser')
#print(soup)
soup.find_all('')
request('https://baike.baidu.com/item/%E7%BD%91%E7%BB%9C%E7%88%AC%E8%99%AB', 'utf-8')
|
|