访问浏览器

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))

posted @ 2020-05-13 16:09  哦噢  阅读(210)  评论(0编辑  收藏  举报