网页内容抓取工具(,涉及Python使用BeautifulSoup模块解析html网页的相关技巧)
优采云 发布时间: 2021-12-26 13:06网页内容抓取工具(,涉及Python使用BeautifulSoup模块解析html网页的相关技巧)
本文主要介绍基于BeautifulSoup抓取网页指定内容的python方法,涉及Python使用BeautifulSoup模块解析html网页的相关技巧。有一定的参考价值,有需要的朋友可以参考
本文示例介绍了基于BeautifulSoup爬取网页指定内容的python方法。分享给大家,供大家参考。具体实现方法如下:
# _*_ 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 编程有所帮助。
以上是基于BeautifulSoup爬取网页指定内容的python方法的详细内容。详情请关注html中文网其他相关文章!