python之BeautifulSoup4的例子

仅作演示用

from bs4 import BeautifulSoup
import urllib.request

webfile = urllib.request.urlopen('http://www.baidu.com')
webcontext = webfile.read().decode("UTF-8")

soup = BeautifulSoup(webcontext,"html.parser")

urlInfo = soup.findAll('div',id = 'u')

print(urlInfo[0].next.text)
print(urlInfo[0].next.get('href'))

 

posted @ 2013-11-04 07:53  自由出土文物  阅读(1061)  评论(0编辑  收藏  举报