首页 > 解决方案 > 抓取 Lazada 数据

问题描述

我使用 Selenium 从 Lazada 网站获取商品名称、价格、评论等数据。但是,它会在第一次刮擦后阻止我。我的问题有没有办法解决这个问题?各位大神能不能给个详细的解决办法。谢谢

标签: seleniumweb-scraping

解决方案


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 中设置代理


推荐阅读