ribbon 发表于 2014-11-29 22:08
以后的处理你可以参考beautiful soup 4.2.0 documentation(Google搜索吧),beautifulsoup很方便的,也不复 ...
大神,请问下述程序有什么错误?能够成功运行但是结果为空。
网址是百度搜索“university”的结果。我想找一下结果中和math相关的网页标题和时间。
import urllib2
url='http://www.baidu.com/s?wd=university&pn=0&oq=university&tn=baiduhome_pg&ie=utf-8&usm=4&rsv_idx=2&rsv_pq=b247bd8100001b24&rsv_t=75f2y6ETpxsjOyy%2Fh5S%2Foe55%2FlLCh1Y87d9bcDBzxDN4bsLRN7YA2umnH%2BzOdHnxI8B1&rsv_spt=1&issp=1&f=8&rsv_bp=0'
content=urllib2.urlopen(url).read()
from BeautifulSoup import BeautifulSoup
soup=BeautifulSoup(content)
siteUrls=soup.findAll('math',attrs={'class':'g'})
siteUrls
而当我把math改为span时就会有较为正常的结果了。。。感觉我没搞明白findAll这个函数,自己看了好久了。求指点。
谢谢!