【发布时间】:2012-10-19 17:10:05
【问题描述】:
谁能给我看一下代码,比如说每 30 分钟从 google 获取一次Recent News,然后使用 python 在我的网站上展示它们?
我观看了 44 个视频教程并学习了基础知识。
一个例子是:
import urllib2
from BeautifulSoup import BeautifulSoup
# or if your're using BeautifulSoup4:
# from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://www.timeanddate.com/worldclock/astronomy.html?n=78').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
但是像我这样的初学者无法理解这段代码如何帮助我解决上面的例子。
【问题讨论】:
-
如果你想显示新闻,你应该使用google rss feed。你不需要网络抓取任何东西,除非你只是为了练习。 example
-
这只是一个例子...我想获得新闻但不是来自 google..
标签: python web-scraping