BeautifulSoup: object of type 'Response' has no len()

前端 未结 7 1528
深忆病人
深忆病人 2020-12-05 09:55

Issue: when I try to execute the script, BeautifulSoup(html, ...) gives the error message \"TypeError: object of type \'Response\' has no len(). I tried passing

7条回答
  •  佛祖请我去吃肉
    2020-12-05 10:45

    you are getting only response code in 'response' and always use browser header for security otherwise you will face many issues

    Find header in debugger console network section 'header' UserAgent

    Try

    import requests
    from bs4 import BeautifulSoup
    
    from fake_useragent import UserAgent
    
    url = 'http://www.google.com'
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) 
    AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}
    
    response = requests.get(quote_page, headers=headers).text
    
    soup = BeautifulSoup(response, 'html.parser')
    print(soup.prettify())
    

提交回复
热议问题