- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Python爬虫实现抓取京东店铺信息及下载图片功能示例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例讲述了Python爬虫实现抓取京东店铺信息及下载图片功能。分享给大家供大家参考,具体如下:
这个是抓取信息的 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from
bs4
import
BeautifulSoup
import
requests
url
=
'https://list.tmall.com/search_product.htm?q=%CB%AE%BA%F8+%C9%D5%CB%AE&type=p&vmarket=&spm=875.7931836%2FA.a2227oh.d100&from=mallfp..pc_1_searchbutton'
response
=
requests.get(url)
#解析网页
soup
=
BeautifulSoup(response.text,
'lxml'
)
#.text将解析到的网页可读
storenames
=
soup.select(
'#J_ItemList > div > div > p.productTitle > a'
) #选择出商店的信息
prices
=
soup.select(
'#J_ItemList > div > div > p.productPrice > em'
) #选择出价格的信息
sales
=
soup.select(
'#J_ItemList > div > div > p.productStatus > span > em'
) #选择出销售额的信息
for
storename, price, sale
in
zip
(storenames,prices,sales):
storename
=
storename.get_text().strip()
#用get_text()方法筛选出标签中的文本信息,由于筛选结果有换行符\n所以用strip()将换行符去掉
price
=
price.get_text()
sale
=
sale.get_text()
print
(
'商店名:%-40s价格:%-40s销售额:%s'
%
(storename,price,sale))
#使打印出来的信息规范
print
(
'----------------------------------------------------------------------------------------------'
)
|
这个是下载图片的 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
from
bs4
import
BeautifulSoup
import
requests
import
urllib.request
url
=
'https://list.tmall.com/search_product.htm?q=%CB%AE%BA%F8+%C9%D5%CB%AE&type=p&vmarket=&spm=875.7931836%2FA.a2227oh.d100&from=mallfp..pc_1_searchbutton'
response
=
requests.get(url)
soup
=
BeautifulSoup(response.text,
'lxml'
)
imgs
=
soup.select(
'#J_ItemList > div > div > div.productImg-wrap > a > img'
)
a
=
1
for
i
in
imgs:
if
(i.get(
'src'
)
=
=
None
):
break
img
=
'http:'
+
i.get(
'src'
)
#这里废了好长的时间,原来网站必须要有http:的
#print(img)
urllib.request.urlretrieve(img,
'%s.jpg'
%
a,
None
,)
a
=
a
+
1
|
ps
1.选择信息的时候用css 。
2.用get_text()方法筛选出标签中的文本信息 。
3.strip,lstrip,rstrip的用法:
Python中的strip用于去除字符串的首尾字符;同理,lstrip用于去除左边的字符;rstrip用于去除右边的字符.
这三个函数都可传入一个参数,指定要去除的首尾字符.
需要注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符,直到没有匹配的字符,比如:
1
2
|
theString
=
'saaaay yes no yaaaass'
print
theString.strip(
'say'
)
|
theString依次被去除首尾在['s','a','y']数组内的字符,直到字符在不数组内。所以,输出的结果为:
yes no 。
比较简单吧,lstrip和rstrip原理是一样的.
注意:当没有传入参数时,是默认去除首尾空格和换行符的.
1
2
3
4
5
|
theString
=
'saaaay yes no yaaaass'
print
theString.strip(
'say'
)
print
theString.strip(
'say '
)
#say后面有空格
print
theString.lstrip(
'say'
)
print
theString.rstrip(
'say'
)
|
运行结果:
yes no es no yes no yaaaass saaaay yes no 。
希望本文所述对大家Python程序设计有所帮助.
原文链接:https://blog.csdn.net/qq_35661436/article/details/52180399 。
最后此篇关于Python爬虫实现抓取京东店铺信息及下载图片功能示例的文章就讲到这里了,如果你想了解更多关于Python爬虫实现抓取京东店铺信息及下载图片功能示例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我在一个网站上工作。 我需要了解我的网站是否获得了来自 Google 或任何其他搜索引擎的抓取工具/机器人的访问 在我的应用程序中,我正在拦截 http 请求。并且需要查明爬虫/机器人是否正在发出 h
我与北京理工大学python爬虫的邂逅 在人生的旅途中,我们时常有机会邂逅一些惊艳的事物,它们仿佛一束亮光照亮了前行的道路。而我,一个平凡的人类,也不例外。回想起那个让我心动的时刻,我想起了与北京理工
从“爬虫”谈起 在这个信息爆炸的时代,互联网上的数据宛如茫茫星海,琳琅满目。但是,我们能否想象到这些数据背后隐藏着多少珍贵的信息呢?有人说,要想获得这些数据,我们需要借助一种神奇的力量——爬虫。 什么
探索未知的领域 曾几何时,我陷入了对互联网世界的好奇之中。作为一个普通的人类,我对于计算机技术的了解可谓是一窍不通。然而,好奇心驱使着我踏上了学习的征途。 奇妙的爬虫 在探索计算机领域的过程中,我翻阅
教室的奇妙之旅 在一个晴朗的早晨,我来到了一所神奇且富有魅力的教室。这里充满了未知的冒险和无限的学习可能。嘿,你没听错,就是那个零基础Python视频教程课程的教室!让我带你一起踏上这趟令人期待的爬虫
零基础学python3 爬虫 嗨,各位小伙伴们!今天要和大家分享一段有关学习Python3爬虫的故事。无论是技术小白还是编程高手,都可以从中获益良多。 1. 邂逅神奇的爬虫世界 就像是迷失在未知之地的
我正在开发一个 Python(3) 程序,在该程序中,我必须使用输入作为表示各种操作的多次迭代列表来返回目录迭代的移动次数,例如: ../ 表示移动到当前文件夹的父文件夹。 ./ 保留在同一文件夹中
我和Python:一段关于爬虫和第三方库的故事 曾经有一个人,他和一门编程语言结下了不解之缘。这门语言就是Python,一个灵活而强大的工具,让他的世界变得多姿多彩。 遇见爬虫:探索未知的世界 某天,
偷心技艺:大众点评TOP10 爬虫 Python 故事发生在一个被互联网包围的城市,充满了各种各样的餐馆、咖啡厅和美食街巷。每天都有无数的食客们纠结于选择哪家餐厅才能获得满足和享受。就在这个时候,我偶
登山寻宝:为什么Python爬虫部分网页源码 人生就像登山寻宝的旅程,充满了未知和挑战。而对于爱好编程的我来说,写一个Python爬虫,探索网络世界也是一种刺激的冒险。今天,我想和大家分享一下为什么要
插班生的悲喜交加 记得那个夏天,我踏入了编程的殿堂,成为了一名程序员。对于一个毫无基础的人来说,这是一次勇敢而激动的尝试。然而,更令我兴奋的是,在我的码农之旅中,我发现了一种神奇的力量——Python
一、 意外的宝藏 当我踏进了编程的大门,发现了那个绚丽多彩的世界时,我仿佛捡到了一个意外的宝藏。在编码的世界里,我像是一个魔术师,用着神奇的符号与逻辑来创造奇迹。然而,随着时间的推移,我渐渐找到了一种
“呜呜呜~” 夏日的阳光穿过微风,洒在我身上,仿佛一片温暖而宁静的海洋。我望着眼前充满希望与挑战的屏幕,满脸的期待和困惑。作为一个刚刚入门的编程初学者,我竭尽全力探索着那座神秘的编程世界,好像是航行在
我的编程之旅 嗨,大家好!我是一个普通的人类,对于编程世界充满着无限的好奇和热情。今天,我想向大家讲述一段关于我的编程经历,特别是在爬虫领域的探索之旅。 1. 踏上未知的征途 就像一只踏上大海的小船,
揭秘神奇的爬虫世界:探寻京东销量数据库 从古至今,人类一直渴望了解世界的各个角落。而对于互联网这个充满未知和神秘的领域来说,我们更是怀着好奇和充满冒险精神的心态去探索。今天,我将带领大家踏上一段激动人
啊!你好呀!很高兴能遇到你,让我向你讲一个关于python爬虫爬取关键词排名的故事。 章节一:奇妙的网络世界 网络就像一片浩瀚的海洋,里面有无数宝藏等待着我们发掘。而当我们学会了使用python这把钥
一次意外的奇遇 在我们生活的世界中,技术如今已经无处不在,无论是大型软件开发还是个人应用,都离不开它的支持。而其中最为神奇的领域之一,就是爬虫技术。想象一下,你有可能仅凭几行代码,就能够在电脑屏幕上将
奇遇之旅 在这个大千世界中,我有幸踏上了一次令人兴奋的冒险之旅。故事的开始,是一个寂静而神秘的夜晚。 迷宫的入口 深夜的城市,街道上弥漫着微弱的灯光,仿佛点缀着无数的星星。我沿着曲径通幽的小巷走着,脚
python 爬虫 自动上传下载 从前有一个热爱编程的小伙子,他喜欢利用自己的技术解决各种实际问题。有一天,他面对一个任务:需要在网络上批量上传和下载文件。这可不是一件轻松的工作,但对于这位小伙子来说
一场奇妙的探险之旅:Python编程语言中的爬虫第三方库 故事从一个寻宝者开始。他身穿一件斑驳的皮衣,手持一柄锈迹斑斑的剑,如同一个当代版的荒野游侠。这位勇士的目标是探索Python编程语言中的神秘领
我是一名优秀的程序员,十分优秀!