【问题标题】:Issue on web-scraping with GET Requests and Beautiful Soup使用 GET 请求和 Beautiful Soup 进行网络抓取的问题
【发布时间】:2020-05-26 11:21:01
【问题描述】:

我正在尝试使用 BeautifulSoup 抓取 URL。

下面是我的代码:

url= 'https://www.clinicspots.com/what-is-the-knee-replacement-surgery-cost-in-india'
response = requests.get(url)

s4 = BeautifulSoup(response.content, 'html.parser')
s4

此外,我需要执行s4.title.text

这给了我一些奇怪的输出(似乎是用中文写的)

我尝试手动打开 URL,这似乎工作正常。

我不确定如何解决这个问题。请提出建议。

编辑#1:下面是输出的屏幕截图:

【问题讨论】:

  • 它给了你什么?你必须向我们展示!否则我们不是这里的翻译服务。您的问题与编程语言有关吗?

标签: python-3.x web-scraping beautifulsoup


【解决方案1】:

使用s4 = BeautifulSoup(response.text, 'html.parser') 而不是s4 = BeautifulSoup(response.content, 'html.parser')

【讨论】:

    【解决方案2】:

    你可以试试:

    headers =  {'User-Agent': 'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0 '}  
    
    url= 'https://www.clinicspots.com/what-is-the-knee-replacement-surgery-cost-in-india'
    response = requests.get(url, headers=headers)
    s4 = BeautifulSoup(response.text, 'lxml')
    print(s4)
    

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多