python web scraper, Response [403]



我正在尝试web抓取一个网站,但我得到了以下错误:

<响应[403]>

当我显示输出时,我得到的是:

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

如果有人能帮我。

感谢

这似乎不是机器人程序拦截程序的问题,请确保您正在抓取的网站没有使用javascript加载其内容,如果使用了javascript,则您必须使用启用javascript的抓取库(如selenium(来让网站加载其内容,然后可能使用beautifulsoup来解析dom。

最新更新