反爬虫類エラー418処理について
正常に爬虫類が
いくつかのウェブサイトを這い出すと、ステータスコード新聞418が出力される.このとき、ウェブページの反爬虫類はrequests.get()に入力されるパラメータheaders
このとき、リクエストにheadersを追加し、正常にheadersを表示するとブラウザのnetworkで表示できます.
import requests
import time
from bs4 import BeautifulSoup
url='https://blog.csdn.net/Xiang_lhh/article/details/104940609'
resp=request.get(url)
bs=BeautifulSoup(resp,'lxml')# beautifulsoup
result=bs.find('p')
print(result.text)
time.sleep(5)
# ,
いくつかのウェブサイトを這い出すと、ステータスコード新聞418が出力される.このとき、ウェブページの反爬虫類はrequests.get()に入力されるパラメータheaders
import requests
import time
from bs4 import BeautifulSoup
url='https://blog.csdn.net/Xiang_lhh/article/details/104940609'
headers={'User-Agent':'','Referer':''}
resp=request.get(url,headers=headers)
bs=BeautifulSoup(resp,'lxml')# beautifulsoup
result=bs.find('p')
print(result.text)
time.sleep(5)
このとき、リクエストにheadersを追加し、正常にheadersを表示するとブラウザのnetworkで表示できます.