我想从网站上获取每日日出/日落时间。是否可以使用 Python 抓取网页内容?使用了哪些模块?有没有可用的教程?
将 urllib2 与出色的BeautifulSoup库结合使用:
import urllib2 from BeautifulSoup import BeautifulSoup # or if you're using BeautifulSoup4: # from bs4 import BeautifulSoup soup = BeautifulSoup(urllib2.urlopen('http://example.com').read()) for row in soup('table', {'class': 'spad'})[0].tbody('tr'): tds = row('td') print tds[0].string, tds[1].string # will print date and sunrise