【发布时间】:2018-01-17 22:56:13
【问题描述】:
我正在尝试编写一个 python 脚本来列出网页中包含某些子字符串的所有链接。我遇到的问题是该网页有多个“页面”,因此它不会弄乱整个屏幕。以https://www.go-hero.net/jam/17/solutions/1/1/C++ 为例。
这是我目前所拥有的:
import requests
from bs4 import BeautifulSoup
url = "https://www.go-hero.net/jam/17/solutions/1/1/C++"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html5lib")
links = soup.find_all('a')
for tag in links:
link = tag.get('href', None)
if link is not None and 'GetSource' in link:
print(link)
关于如何让它发挥作用的任何建议?提前致谢。
【问题讨论】: