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)