【发布时间】:2019-09-26 14:13:41
【问题描述】:
我不想用我的基本问题惹恼你,但我被困住了,希望你能帮助我。 我已经完成了教程并观看了许多视频,但我无法弄清楚我做错了什么。 我想从这个表中抓取数据:https://www.youpriboo.com/vorher_102_main_nat.php?action=show&liga=2.BL
这是我的代码:
import requests
from bs4 import BeautifulSoup
base_URL = 'https://www.youpriboo.com/vorher_102_main_nat.php?action=show&liga='
liga = '2.BL'
URL = base_URL + liga
headers = {
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36:'}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
for name in soup.find_all("td", class_="hac"):
name1 = name.parent.find_all('td')[1] # team1
name2 = name.parent.find_all('td')[2] # team2
wahr1 = name.parent.find_all('td')[6] # wahr1
print(name1.get_text() +' '+ name2.get_text()+' '+ wahr1.get_text())
问题是它给了我 3 次数据,并且在游戏之间列出了 3 个数字。
预期结果如下所示:
Armina Bielefeld VfB Stuttgart 34,43
SV Wehen Wiesbaden VfL Osnabrück 34,51
(and so on)
感谢您的时间和工作!
我也在这里发布了这个:https://www.reddit.com/r/Python/comments/d9km7y/scraping_data_using_bs4_gives_me_unexpected/
【问题讨论】:
标签: python-3.x web-scraping beautifulsoup