PYthon新手求助一个问题,想不通各位老师帮忙解答下
#_*_ coding="UFT-8" _*_import os,sys,time
import requests
from bs4 import BeautifulSoup
import re
#______________________________________
def download(html:str):
rr=requests.get(html)
soup2=BeautifulSoup(rr.text,'html.parser')
gamedownload={}
for dl in soup2.find_all('a',class_="omsc-button omsc-no-custom-hover omsc-size-medium omsc-with-icon omsc-style-flat omsc-text-bright"):
print(dl.get('href'))
#---------------------------------------
def main():
url="https://truckgame.cn/game"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'}
r=requests.get(url,headers=headers)
soup=BeautifulSoup(r.text,'html.parser')
game={}
dizhi=[]
for s in soup.find_all('div',class_="row postLists lists"):
for j in s.find_all('div',{"class":"col-xxs-6 col-xs-4 col-sm-6 col-md-4 col-lg-3 post-card-wrapper"}):
game={
'游戏名':j.find('h2').string,
'链接':download(str(j.find('a',class_="cover").get('href')))
}
print(game)
if __name__ == '__main__':
main()
上面的结果 居然游戏地址在上面,反而字典里的链接是NONE值 奇怪了 ,这是哪里不对啊!!!为什么!! 求各位大佬 download函数只有print没有return数据啊 楼上正解 def download(html:str):
rr=requests.get(html)
soup2=BeautifulSoup(rr.text,'html.parser')
gamedownload={}
for dl in soup2.find_all('a',class_="omsc-button omsc-no-custom-hover omsc-size-medium omsc-with-icon omsc-style-flat omsc-text-bright"):
# print(dl.get('href'))
return dl.get('href') 解决了 谢谢楼上老师
页:
[1]