狂暴版——豌豆荚信息获取

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
def get_good(driver,number):
    try:
        time.sleep(5)
        js_code = '''
                        window.scrollTo(0,5000)
                '''
        driver.execute_script(js_code)
        time.sleep(5)
        good_list = driver.find_elements_by_class_name('card')
        for good in good_list:
            good_name = good.find_element_by_class_name('app-title-h2').text
            good_url =  good.find_element_by_css_selector('.app-title-h2 a').get_attribute('href')
            good_people_size = good.find_element_by_class_name('meta').text
            good_commit = good.find_element_by_class_name('comment').text
            good_content = f'''
            序号:{number}
            游戏名称:{good_name}
            游戏链接:{good_url}
            游戏下载人数_游戏大小:{good_people_size}
            游戏评价: {good_commit}
            \n
            '''
            print(good_content)
            with open('wandou1.text','a',encoding='utf-8') as f:
                f.write(good_content)
            number+=1
        print("游戏信息写入成功!!")
        more_load=driver.find_element_by_class_name('load-more')
        more_load.click()
        time.sleep(2)
        get_good(driver,number)
    finally:
        driver.close()
if __name__ == '__main__':
    driver=webdriver.Chrome()
    try:
        num=1
        driver.implicitly_wait(5)
        driver.get('https://www.wandoujia.com/category/6001')
        get_good(driver,num)
    finally:
        driver.close()

 

转载于:https://www.cnblogs.com/wsh123/p/11128812.html

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页