python基于BeautifulSoup實現(xiàn)抓取網(wǎng)頁指定內容的方法
更新時間:2015年07月09日 10:12:50 作者:光索與諾
這篇文章主要介紹了python基于BeautifulSoup實現(xiàn)抓取網(wǎng)頁指定內容的方法,涉及Python使用BeautifulSoup模塊解析html網(wǎng)頁的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了python基于BeautifulSoup實現(xiàn)抓取網(wǎng)頁指定內容的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
# _*_ coding:utf-8 _*_ #xiaohei.python.seo.call.me:) #win+python2.7.x import urllib2 from bs4 import BeautifulSoup def 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程序設計有所幫助。
您可能感興趣的文章:
- python BeautifulSoup使用方法詳解
- Python BeautifulSoup [解決方法] TypeError: list indices must be integers or slices, not str
- Python BeautifulSoup中文亂碼問題的2種解決方法
- python 解析html之BeautifulSoup
- Python爬蟲庫BeautifulSoup獲取對象(標簽)名,屬性,內容,注釋
- python中bs4.BeautifulSoup的基本用法
- Python使用BeautifulSoup庫解析HTML基本使用教程
- python爬蟲之BeautifulSoup 使用select方法詳解
- python爬蟲入門教程--HTML文本的解析庫BeautifulSoup(四)
- 從零開始學習Python與BeautifulSoup網(wǎng)頁數(shù)據(jù)抓取
相關文章
基于virtualenv創(chuàng)建python虛擬環(huán)境過程圖解
這篇文章主要介紹了基于virtualenv創(chuàng)建python虛擬環(huán)境過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-03-03Python推導式簡單示例【列表推導式、字典推導式與集合推導式】
這篇文章主要介紹了Python推導式,結合簡單實例形式分析了Python列表推導式、字典推導式與集合推導式基本使用方法,需要的朋友可以參考下2018-12-12