首页 > 编程 > Python > 正文

python基于BeautifulSoup实现抓取网页指定内容的方法

2019-11-25 17:12:44
字体:
来源:转载
供稿:网友

本文实例讲述了python基于BeautifulSoup实现抓取网页指定内容的方法。分享给大家供大家参考。具体实现方法如下:

# _*_ 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程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表