selenium采集1688简单信息

1688信息采集

首先进入1688可以看见多种类别信息
类别
我们选择其中的一种,例如选择女装之后,又会有很多的类别
类别
将类别保存到列表,方便下面继续运行

detail_urls = []

categories = driver.find_elements_by_xpath("//div[@class='ch-menu-item']/div[@class='ch-menu-item-list']/ul[@class='fd-clr']/li[@class='item']/a")
for category in categories:
    url = category.get_attribute('href')
    detail_urls.append(url)

xpath获取所有类别的url
xpath获取
遍历进入,进入后数据是Ajax动态的方式加载
我们可以模拟鼠标下滑,一直加载,达到页面底部的时候退出循环
示例代码如下:

t = True
while t:
    check_height = driver.execute_script("return document.body.scrollHeight;")

    js = "var q=document.documentElement.scrollTop=20000"  # documentElement表示获取根节点元素
    driver.execute_script(js) # 执行js
    time.sleep(3.0)  # 加载数据不能过快,否则不能下滑

    check_height1 = driver.execute_script("return document.body.scrollHeight;")
    if check_height
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值