访问浏览器
import requests from bs4 import BeautifulSoup def getHTMLText(url): try: r=requests.get(url,timeout=30) soup=BeautifulSoup(r.text) r.raise_for_status() r.encoding='utf-8' return r.text,r.status_code,len(r.text),r.encoding,len(soup.text) except: return "" url="https://www.baidu.com/" for i in range(20): print(i) print(getHTMLText(url))