【问题标题】:unable to get response even by using Fake User Agent即使使用假用户代理也无法得到响应
【发布时间】:2020-11-09 18:27:33
【问题描述】:

我正在尝试抓取一个网站,但输出为 None。 这是我的代码:

from bs4 import BeautifulSoup
import requests
from fake_useragent import UserAgent
ua=UserAgent()
header={'user-agent':ua.chrome}
responsejustdial=requests.get('https://www.justdial.com/Delhi/Builders-in-Faridabad/nct-10059255',headers=header)
print(responsejustdial)

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    将您的标题更改为与此示例相同:

    import requests
    from bs4 import BeautifulSoup
    
    HEADERS = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
    }
    
    responsejustdial = requests.get('https://www.justdial.com/Delhi/Builders-in-Faridabad/nct-10059255', headers=HEADERS)
    >>> print(responsejustdial)
    <Response [200]>
    

    【讨论】:

      猜你喜欢
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      相关资源
      最近更新 更多