我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。
关闭3年前。
我想从网站获取每日日出/日落时间。是否可以使用 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
https://stackoverflow.com/questions/2081586/