将“tag.find_all”用于具有随机数的访问器 (BeautifulSoup)
Using `tag.find_all` for an accessor with random numbers (BeautifulSoup)
<a href="some_url" game_id="Some integers"</a>
"Some integers" 是在每个 href link.
中变化的数字
我想从中提取 href "some url"。
我现在的代码:
for link in table.find_all("a",{"game_id":?}):
href=link.get(href)
我应该在 "game_id" 中输入什么:问号以便代码可以检测到 href links?
首先,您需要 regex
来处理。
import re
for link in table.find_all('a', {'game_id' : re.compile('\d+')}):
href = link.get("href") # or href = link["href"]
此外,您可以使用双引号来访问 href
字段。
<a href="some_url" game_id="Some integers"</a>
"Some integers" 是在每个 href link.
中变化的数字我想从中提取 href "some url"。
我现在的代码:
for link in table.find_all("a",{"game_id":?}):
href=link.get(href)
我应该在 "game_id" 中输入什么:问号以便代码可以检测到 href links?
首先,您需要 regex
来处理。
import re
for link in table.find_all('a', {'game_id' : re.compile('\d+')}):
href = link.get("href") # or href = link["href"]
此外,您可以使用双引号来访问 href
字段。