python - 使用 python 抓取具有多个部分的页面
解决方案
https://www.transfermarkt.co.uk/yvon-mvogo/profil/spieler/147051
https://www.transfermarkt.co.uk/steve-von-bergen/profil/spieler/4793
https://www.transfermarkt.co.uk/scott-sutter/profil/spieler/34520
上面给出了一些玩家资料的链接。您可以在 BeautifulSoup 中打开页面并对其进行解析以获取其中的所有链接。在后面写一个正则表达式,只过滤出满足上述模式的链接,并编写另一个函数从个人资料页面中提取信息
soup = BeautifulSoup(html_page,'html.parser')
for a in soup.find_all('a', href=True):
m = re.search('/[a-z\-]+/profil/spieler/[0-9]+', a['href'])
if m:
found = m.group(0)
print(found)
输出
/michael-frey/profil/spieler/147043
/yvon-mvogo/profil/spieler/147051
/scott-sutter/profil/spieler/34520
/leonardo-bertone/profil/spieler/194975
/steve-von-bergen/profil/spieler /4793
/alain-nef/profil/spieler/4945
/raphael-nuzzolo/profil/spieler/32574
/marco-wolfli/profil/spieler/4860
/moreno-costanzo/profil/spieler/41207
/jan-lecjaks/profil/spieler /62854
/alain-rochat/profil/spieler/4843
/christoph-spycher/profil/spieler/2871
/gonzalo -zarate/profil/spieler/
52731 /christian-schneuwly/profil/spieler/52556
/yuya-kubo/profil/spieler /186260
/alexander-farnerud/profil/spieler/10255
/salim-khelifi/profil/spieler/147049
/alexander-gerndt/profil/spieler/45881
/adrian-winter/profil/spieler/59681
/victor-palsson/profil/spieler/97241
/milan-gajic/profil/spieler/46928
/dusan-veskovac/profil/spieler/28705
/marco-burki/profil/spieler/172192
/elsad-zverotic/profil/spieler/25542
/pa-modou/profil/spieler/66449
/yoric-ravet/profil/spieler/82461
您可以遍历所有链接并调用从配置文件页面中提取所需信息的函数。希望这可以帮助
使用此链接。我通过检查按钮得到它
https://www.transfermarkt.co.uk/michael-frey/gemeinsameSpiele/spieler/147043/ajax/yw2/page/1
您可以更改末尾的数字以获取每个页面
推荐阅读
- postgresql - 将十进制转换为字符 postgres
- flutter - flutter_map - 为什么位置在变化,而地图没有移动?
- c# - 用于将给定类型的任何模式转换为通用类型的通用 JSON
- sql-server - 使用 excel vba 和 where 语句从 mssql 中选择数据
- ios - Apple 将停止接受使用 UIWebView API 的应用提交
- oracle - T-SQL 到 PL/SQL - 使用临时变量和“INTO”表达式在 Oracle DB 中搜索查询的总数
- asp.net-mvc - Azure 媒体播放器 - 从中断的地方继续播放
- python - 我是 python 新手,为什么冒号是无效的语法?
- amazon-web-services - S3 Bucket without ACL - No permission
- twilio - 如何在 C# 的 API 请求中检索第 3 方请求的主机名/dns