本文實例講述了python基于BeautifulSoup實現(xiàn)抓取網(wǎng)頁指定內(nèi)容的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
# _*_ coding:utf-8 _*_#xiaohei.python.seo.call.me:)#win+python2.7.ximport urllib2from bs4 import BeautifulSoupdef jd(url): page = urllib2.urlopen(url) html_doc = page.read() soup = BeautifulSoup(html_doc.decode('gb2312','ignore')) for i in soup.find_all('div', id="sortlist"): one = i.find_all('a') two = i.find_all('li') print ("%s %s" % (one,two))jd("http://channel.jd.com/computer.html")希望本文所述對大家的Python程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選