【发布时间】:2020-01-10 09:48:03
【问题描述】:
我遇到了一个问题,即并非所有实例都在相对简单的 beautifulsoup 抓取中捕获。我正在运行的是以下内容:
from bs4 import BeautifulSoup as bsoup
import requests as reqs
home_test = "https://fbref.com/en/matches/033092ef/Northampton-Town-Lincoln-City-August-4-2018-League-Two"
away_test = "https://fbref.com/en/matches/ea736ad1/Carlisle-United-Northampton-Town-August-11-2018-League-Two"
page_to_parse = home_test
page = reqs.get(page_to_parse)
status_code = page.status_code
status_code = str(status_code)
parse_page = bsoup(page.content, 'html.parser')
find_stats = parse_page.find_all('div',id="team_stats_extra")
print(find_stats)
for stat in find_stats:
add_stats = stat.find_next('div').get_text()
print(add_stats)
如果您查看第一次打印,则抓取会捕获我所追求的网站部分,但是如果您检查第二次打印,则实际上并没有处理较早的一半实例一点也不。我对此没有任何限制,所以理论上它应该包含所有正确的。
我已经测试了很多不同的 find_next、find 或 find_all 变体,但第二个循环 find 永远不会使用所有这些变体。
结果总是:
Northampton Lincoln City
12Fouls13
6Corners1
7Crosses2
89Touches80
它应该采取以下措施:
Northampton Lincoln City
12Fouls13
6Corners1
7Crosses2
89Touches80
Northampton Lincoln City
2Offsides2
9Goal Kicks15
32Throw Ins24
18Long Balls23
【问题讨论】:
标签: python html web-scraping beautifulsoup