python reptiles: crawling peas APP first page data information (Selenium)

from selenium import webdriver
import time

driver = webdriver.Chrome(r'C:\Users\Auraro\Desktop/chromedriver.exe')

try:
    driver.implicitly_wait(20)
    driver.get('https://www.wandoujia.com/category/6001')

    time.sleep(5)
    js_code = '''
                   window.scrollTo(0,5000)
                   '''
    driver.execute_script(js_code)

    time.sleep(5) # 商品信息加载,等待5s
    app_list = driver.find_elements_by_class_name('card')
    for app in app_list:
        # app名称
        app_name = app.find_element_by_css_selector('.app-title-h2 a').text

        # 详情页url
        . detail_url = app.find_element_by_css_selector ( '. App title-h2-A') get_attribute ( 'href') 

        # number of downloads 
        # app size 
        . download_num_size = app.find_element_by_class_name ( 'Meta') text 

        app_content = "" " 
            App name: { } 
            details page url: {} 
            number of downloads: {} 
            App size: {} 
            \ n- 
        "" ".format (APP_NAME, detail_url, download_num_size [:. 8], download_num_size [. 11:]) 
        Print (app_content) 
        with Open ( 'pea pods app.txt ',' A ', encoding =' UTF-. 8 ') AS F: 
            f.write (app_content) 
    the time.sleep (. 3) 


the finally: 
    driver.close ()

  

Guess you like

Origin www.cnblogs.com/Auraro997/p/11128757.html