python基于BeautifulSoup实现抓取网页指定内容的方法
作者:光索与诺 时间:2022-11-29 12:11:48
本文实例讲述了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程序设计有所帮助。
标签:python,BeautifulSoup,抓取
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ASP.NET MVC实现区域或城市选择
2023-07-13 17:50:00
![](https://img.aspxhome.com/file/2023/1/78991_0s.png)
详解用Node.js实现Restful风格webservice
2024-05-13 09:35:20
![](https://img.aspxhome.com/file/2023/8/125718_0s.png)
详解python文件的操作和异常的处理
2021-06-07 04:05:37
![](https://img.aspxhome.com/file/2023/4/131264_0s.jpg)
Python基础之输入,输出与高阶赋值详解
2023-05-21 10:00:32
Python读取YAML文件过程详解
2021-04-21 07:12:25
在CMD命令行中运行python脚本的方法
2023-08-03 18:54:38
![](https://img.aspxhome.com/file/2023/9/60939_0s.jpg)
python和shell获取文本内容的方法
2023-06-20 05:42:35
sklearn线性逻辑回归和非线性逻辑回归的实现
2021-06-16 04:04:31
![](https://img.aspxhome.com/file/2023/3/72213_0s.png)
使用VS2005调试ASP程序方法
2007-11-02 09:56:00
![](https://img.aspxhome.com/file/UploadPic/200711/2/200711210317494s.jpg)
Yii2结合Workerman的websocket示例详解
2023-11-17 04:48:40
详解Python如何查看一个函数的参数
2023-05-13 19:24:19
详解python数组中的符号...与:符号的不同之处
2022-10-14 19:12:37
Golang HTTP 服务平滑重启及升级的思路
2024-02-02 18:05:42
![](https://img.aspxhome.com/file/2023/9/107369_0s.png)
详解tensorflow载入数据的三种方式
2023-07-22 19:35:56
![](https://img.aspxhome.com/file/2023/4/62904_0s.jpg)
这十大Python库你真应该知道
2022-09-20 00:09:03
![](https://img.aspxhome.com/file/2023/0/134990_0s.jpg)
Tensor 和 NumPy 相互转换的实现
2023-07-05 04:55:51
mysql 超大数据/表管理技巧
2024-01-16 22:14:05
python 怎样将dataframe中的字符串日期转化为日期的方法
2022-09-14 16:21:49
Python机器学习NLP自然语言处理Word2vec电影影评建模
2022-09-07 09:40:35
![](https://img.aspxhome.com/file/2023/5/112515_0s.gif)
SqlServer数据库全角转换成半角
2024-01-21 11:20:39