我正在尝试在上刮一个网站,但我得到了以下错误:
当我显示输出时,我得到如下信息:
<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>
在网上查看之后,我发现我们需要添加一个标题,否则websit就会知道这是一个机器人。我已经把它加进去了,但还是错误。
我使用的代码:
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")
如果有人能帮我的话。
谢谢
发布于 2021-06-07 20:53:07
这似乎不是bot拦截器的问题,请确保您正在抓取的网站不使用javascript加载其内容,如果使用javascript加载其内容,则必须使用启用javascript的刮取库(例如selenium )让网站加载其内容,然后使用漂亮的汤来解析dom。
https://stackoverflow.com/questions/67878412
复制相似问题