• 京东商品 + selenium



    from selenium import webdriver
    import time
    from selenium.webdriver.common.keys import Keys
    bro=webdriver.Chrome()
    
    def get_goods(bro):
        li_list=bro.find_elements_by_class_name('gl-item')
        for li in li_list:
            url=li.find_element_by_css_selector('.p-img>a').get_attribute('href')
            url_img=li.find_element_by_css_selector('.p-img img').get_attribute("src")
            if not url_img:
                url_img='https:'+li.find_element_by_css_selector('.p-img img').get_attribute("data-lazy-img")
            price=li.find_element_by_css_selector('.p-price i').text
            name=li.find_element_by_css_selector('.p-name em').text
            commit=li.find_element_by_css_selector('.p-commit a').text
    
            print('''
            商品名字:%s
            商品价格:%s
            商品图片地址:%s
            商品地址:%s
            商品评论数:%s
            '''%(name,price,url,url_img,commit))
    
        #查找下一页按钮
        next = bro.find_element_by_partial_link_text('下一页')
        time.sleep(2)
        a = next.click()
        next.click()
        #继续抓取下一页
        get_goods(bro)
        time.sleep(5)
    
    try:
        bro.get('https://www.jd.com')
        #隐士等待
        bro.implicitly_wait(10)
        input_search=bro.find_element_by_id('key')
        input_search.send_keys("苹果11pro")
        #模拟键盘操作(模拟键盘敲回车)
        input_search.send_keys(Keys.ENTER)
        get_goods(bro)
    
    except Exception as e:
        print(e)
    finally:
        bro.close()
    

  • 相关阅读:
    第十一周学习总结
    个人冲刺——(六)
    第二阶段冲刺—第二天
    软件工程第十四周总结
    第二阶段冲刺—第一天
    大道至简阅读笔记02
    输入法用户体验评价
    软件工程第十三周总结
    人机交互-水王
    大道至简阅读笔记01
  • 原文地址:https://www.cnblogs.com/kai-/p/12667786.html
Copyright © 2020-2023  润新知