2017-07-13 12 views
0

私は美しいスープの次のリンクを解析しようとしていますが、私はこれを行う最良の方法が何であるか正確にはわかりません。どんな提案も大歓迎です。誰もが今まで興味を持っている場合は美味しいスープのリンクを取得

おかげ

enter image description here

答えて

0

は、私がこれを行う方法を考え出し:

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