【发布时间】:2017-07-13 03:18:55
【问题描述】:
【问题讨论】:
标签: beautifulsoup
【问题讨论】:
标签: beautifulsoup
如果有人有兴趣,我想出了如何做到这一点:
from bs4 import BeautifulSoup
xml = requests.get("http://www.realclearpolitics.com/epolls/2010/governor/2010_elections_governor_map.html").text
def find_governor_races(html):
soup = BeautifulSoup(html, 'html.parser')
pattern = "http://www.realclearpolitics.com/epolls/????/governor/??/*-*.html"
links = []
for option in soup.find_all('option'):
links.append(option['value'])
matched_links = []
for link in links:
if fnmatch(link, pattern):
matched_links.append(link)
return matched_links
【讨论】: