【发布时间】:2021-10-10 10:42:38
【问题描述】:
我有以下网址https://www.gbgb.org.uk/greyhound-profile/?greyhoundId=517801,其中最后 6 位数字是特定跑步者的唯一标识符。我想在此页面上查找所有 6 位唯一标识符。
我试图抓取页面上的所有网址(代码如下所示),但不幸的是我只得到了一个高级摘要。而不是应该包含> 5000名跑步者的深度列表。我希望得到一个列表/数据框,其中显示:
-
https://www.gbgb.org.uk/greyhound-profile/?greyhoundId=517801
-
https://www.gbgb.org.uk/greyhound-profile/?greyhoundId=500000
-
https://www.gbgb.org.uk/greyhound-profile/?greyhoundId=500005
等等
这是我迄今为止能够做到的。感谢您的帮助!
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import re
req = Request("https://www.gbgb.org.uk//greyhound-profile//")
html_page = urlopen(req)
soup = BeautifulSoup(html_page, "lxml")
links = []
for link in soup.findAll('a'):
links.append(link.get('href'))
print(links)
提前感谢您的帮助!
【问题讨论】:
-
您访问的网页(
https://www.gbgb.org.uk//greyhound-profile//)没有...?greyhoundId=xxxxxx的url -
这很奇怪,因为gbgb.org.uk/greyhound-profile/?greyhoundId=517801 肯定是一个页面。此外,当我使用我的代码时,它会获取所有高级 URL,即“gbgb.org.uk/about”和“gbgb.org.uk/welfare-care”。知道我需要做什么才能深入了解gbgb.org.uk/greyhound-profile/?greyhoundId=xxxxxx
-
什么是“高级摘要”?您是否 100% 确定您获得了带有
requests的真实呈现的网页? -
这是我的列表形式的结果的 sn-p。 'gbgb.org.uk'、'gbgb.org.uk/about'、'gbgb.org.uk/welfare-care'、'gbgb.org.uk/racing'、'gbgb.org.uk/rules-regulation'、'#search'、'gbgb.org.uk/my-kennel'、'gbgb.org.uk/about/about-us。我需要获取所有 gbgb.org.uk/greyhound-profile/?greyhoundId=xxxxxx 其中“xxxxxx”是 6 整数唯一标识符。谢谢
-
为什么不在 for 循环中尝试所有 6 位整数?
标签: python selenium url web-scraping beautifulsoup