js 抓取网页内容(,涉及Python使用BeautifulSoup模块解析html网页的相关技巧)
优采云 发布时间: 2021-11-06 16:27js 抓取网页内容(,涉及Python使用BeautifulSoup模块解析html网页的相关技巧)
本文文章主要介绍基于BeautifulSoup爬取网页指定内容的python方法。涉及Python使用BeautifulSoup模块解析html网页的相关技巧。有一定的参考价值,有需要的朋友可以参考
本文介绍了python如何基于BeautifulSoup抓取网页指定内容的示例。分享给大家,供大家参考。具体实现方法如下:
# _*_ 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中文网站文章!