python爬虫:爬取豌豆荚APP第一页数据信息(requests)

时间:2022-09-18 17:29:34
import requests
from bs4 import BeautifulSoup

web='https://www.wandoujia.com/category/6001'
web_g=requests.get(web)
web_code=BeautifulSoup(web_g.text,'lxml')

name=web_code.find_all(name='li',class_='card')

for i in name:
    game_name=i.h2.a.text
    game_url=i.h2.a.attrs['href']
    game_dl=i.find(class_='install-count').text
    game_size=i.find(class_='meta').find_all(name='span')[2].attrs['title']

    game='''
        游戏名称:{}
        地址:{}
        下载量:{}
        游戏大小:{}
        \n
    '''.format(game_name,game_url,game_dl,game_size)
    print(game)
    with open('game_list','a',encoding='utf-8') as f:
        f.write(game)