selenium - 抓取 Lazada 数据
问题描述
我使用 Selenium 从 Lazada 网站获取商品名称、价格、评论等数据。但是,它会在第一次刮擦后阻止我。我的问题有没有办法解决这个问题?各位大神能不能给个详细的解决办法。谢谢
解决方案
Lazada 具有高安全性,要在不阻塞的情况下获取数据,您必须使用代理。你甚至可以使用 python 请求获取数据尝试下面的代码
cookies = {
"user": "en"
}
req_headers = {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"x-requested-with": "XMLHttpRequest",
}
proxies = {"https": "http://000.0.0.0:0000"}
response_data = requests.get(product_url, headers=req_headers, cookies=cookies, proxies=proxies, verify=False)
您可以从响应文本中获取产品数据。要获得评论,您可以使用此网址:
host = "lazada.sg" // you can use any region here
"https://my.{}/pdp/review/getReviewList?itemId={}&pageSize=100&filter=0&sort=1&pageNo={}".format(host,item_id,page_no)
如果你想使用 selenium,你需要在 selenium 中设置代理
推荐阅读
- node.js - 如何在单独的文件nodejs中编写cronjobs
- spring - 我们可以使用 Couchbase 作为 Spring Integration 的消息存储吗
- nuget - 在 NuGet 包中包含引用的项目
- hadoop - 在 hive 中将 bigint 转换为十进制(18,5)
- amazon-web-services - 如何通过 ASP.NET Core 中的端点在 AWS S3 存储桶中上传文件
- if-statement - 如何在 python 中使用带有 if 语句的 while 循环?
- javascript - 如何在 django 模板中实现 javascript 代码?
- python - 异步 FIFO 节流器
- regex - perl 使用哈希和 tr 替换字符串字符
- reactjs - Windows 10 错误->“。” 未被识别为内部或外部命令