0

Here's the website: http://scores.suntimes.com/sports-scores/Hockey-Scores-Matchups.aspx?Year=2013&Period=0119&CurrentSeason=2012-2013

Now, unlike the yahoo page I did earlier, the date here seems to be enclosed like this:

<div id="Scoreboard_6_National_Hockey_League">
         <div class="sdi-title-page-section">National Hockey League</div>
         <div class="sdi-nfl-dates">Saturday, January 19, 2013</div>

So if I wanted to extract that date, how would I word it out in Python?

4

1 回答 1

1

BeautifulSoup

>>> from bs4 import BeautifulSoup as BS
>>> html = """<div id="Scoreboard_6_National_Hockey_League">
...          <div class="sdi-title-page-section">National Hockey League</div>
...          <div class="sdi-nfl-dates">Saturday, January 19, 2013</div>"""
>>> soup = BS(html)
>>> print soup.find('div', {'class':'sdi-nfl-dates'}).text
Saturday, January 19, 2013
于 2013-08-22T02:03:05.407 回答