我正在尝试从以下站点抓取匹配数据
https://sport-tv-guide.live/live/darts
数据正在无误地抓取,但输出未按预期显示。我相信这是因为我错误地调用了 for 循环(参见下面的代码和输出)
import requests
from bs4 import BeautifulSoup
def makesoup(url):
cookies = {'mycountries' : '101,28,3,102,42,10,18,4,2'}
r = requests.post(url, cookies=cookies)
return BeautifulSoup(r.text,"lxml")
def matchscrape(g_data):
for match in g_data:
scheduled = match.findAll('div', class_='main time col-sm-2 hidden-xs')
details = match.findAll('div', class_='col-xs-6 mobile-normal')
for schedule in scheduled:
print("DateTimes; ", schedule.text.strip())
for detail in details:
print("Details:", detail.text.strip())
def matches():
soup=makesoup(url = "https://sport-tv-guide.live/live/darts")
matchscrape(g_data = soup.findAll("div", {"class": "listData"}))
上面的代码提供了以下输出:
然后我尝试按照下面的代码更改 for 循环的位置
import requests
from bs4 import BeautifulSoup
def matchscrape(g_data):
for match in g_data:
scheduled = match.findAll('div', class_='main time col-sm-2 hidden-xs')
details = match.findAll('div', class_='col-xs-6 mobile-normal')
for schedule in scheduled:
print("DateTimes; ", schedule.text.strip())
for detail in details:
print("Details:", detail.text.strip())
但我收到以下输出
我试图获得的输出是
感谢任何可以提供建议或提供解决方案的人。
慕运维8079593
相关分类