我想知道是否有办法在我的Python程序中将Google的搜索结果显示为输出。就像我在程序中输入“电力”一样,我希望将Google的搜索结果显示为纯文本。有办法吗?
更新
import urllib2
response = urllib2.urlopen("https://en.wikipedia.org/wiki/Machine_learning")
the_page = response.read(bytes)
content = str(the_page)
print the_page
我尝试了上面的代码,但是如果我输入
,它会显示错误the_page = response.read()
print the_page
它只是打印页面的HTML格式而不是文本字符串,所以如何单独获取字符串?
答案 0 :(得分:0)
import urllib2
response = urllib2.urlopen("https://en.wikipedia.org/wiki/Machine_learning")
content= response.read()
# Now it's time for parsing *content* to extract the relevant data
# Use regex, HTMLParser from standard library
# or use beautifulsoup, LXML (third party)