Day---03 例子:爬取豌豆荚游戏页面信息

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,2500)
        '''
        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_content = f'''
            游戏序号:{number}
            游戏名称:{good_name}
            游戏链接:{good_url}
            游戏下载人数_游戏大小:{good_people_size}
            \n
            '''

            print(good_content)

            with open('wandoujia.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(5)

        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/gumball/p/11129432.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值