【问题标题】:python web scraper, Response [403]python网络爬虫,响应[403]
【发布时间】:2021-06-07 20:37:11
【问题描述】:

我正在尝试抓取一个网站,但出现以下错误:

当我显示输出时,我得到了这个:

<body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script>var dd={\'cid\':\'AHrlqAAAAAMAFuvaKabaZaMAVsjd8A==\',\'hsh\':\'05B30BD9055986BD2EE8F5A199D973\',\'t\':\'fe\',\'s\':2089,\'host\':\'geo.captcha-delivery.com\'}</script><script src="https://ct.captcha-delivery.com/c.js"></script>

在网上查了一下,我发现我们需要添加一个标题,否则网站会知道这是一个机器人。我已经添加了它,但仍然是错误。

我正在使用的代码:

from IPython.display import Image
import requests
from bs4 import BeautifulSoup
import requests_cache
import pandas as pd
requests_cache.install_cache("bases_scraping", expire_after=10e5)

url = "https://www.leboncoin.fr/recherche?category=55&text=electric%20bike&locations=r_12"

headers = {"user-agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0"}

response = requests.get(url, headers=headers)
print(response)
print(response.content, "html.parser")

如果有人可以帮助我。

谢谢

【问题讨论】:

  • 我们需要查看实际的 URL。你的headers可能有问题
  • 我已经更新了网址

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


【解决方案1】:

这似乎不是机器人拦截器的问题,请确保您正在抓取的网站不使用 javascript 来加载其内容,如果是,那么您将不得不使用启用 javascript 的抓取库,例如selenium 让网站加载其内容,然后可能使用 beautifulsoup 解析 dom。

【讨论】:

    猜你喜欢
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多