- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例讲述了python3爬虫爬取英雄联盟高清桌面壁纸功能。分享给大家供大家参考,具体如下:
使用scrapy爬虫抓取英雄联盟高清桌面壁纸 。
源码地址:https://github.com/snowyme/loldesk 。
开始项目前需要安装python3和scrapy,不会的自行百度,这里就不具体介绍了 。
首先,创建项目 。
1
|
scrapy startproject loldesk
|
生成项目的目录结构 。
首先需要定义抓取元素,在item.py中,我们这个项目用到了图片名和链接 。
1
2
3
4
5
|
import
scrapy
class
loldeskitem(scrapy.item):
name
=
scrapy.field()
imgurl
=
scrapy.field()
pass
|
接下来在爬虫目录创建爬虫文件,并编写主要代码,loldesk.py 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import
scrapy
from
loldesk.items
import
loldeskitem
class
loldeskpiderspider(scrapy.spider):
name
=
"loldesk"
allowed_domains
=
[
"www.win4000.com"
]
# 抓取链接
start_urls
=
[
'http://www.win4000.com/zt/lol.html'
]
def
parse(
self
, response):
list
=
response.css(
".left_bar ul li"
)
for
img
in
list
:
imgurl
=
img.css(
"a::attr(href)"
).extract_first()
imgurl2
=
str
(imgurl)
next_url
=
response.css(
".next::attr(href)"
).extract_first()
if
next_url
is
not
none:
# 下一页
yield
response.follow(next_url, callback
=
self
.parse)
yield
scrapy.request(imgurl2, callback
=
self
.content)
def
content(
self
, response):
item
=
loldeskitem()
item[
'name'
]
=
response.css(
".pic-large::attr(title)"
).extract_first()
item[
'imgurl'
]
=
response.css(
".pic-large::attr(src)"
).extract()
yield
item
# 判断页码
next_url
=
response.css(
".pic-next-img a::attr(href)"
).extract_first()
allnum
=
response.css(
".ptitle em::text"
).extract_first()
thisnum
=
next_url[
-
6
:
-
5
]
if
int
(allnum) >
int
(thisnum):
# 下一页
yield
response.follow(next_url, callback
=
self
.content)
|
图片的链接和名称已经获取到了,接下来需要使用图片通道下载图片并保存到本地,pipelines.py:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
from
scrapy.pipelines.images
import
imagespipeline
from
scrapy.exceptions
import
dropitem
from
scrapy.http
import
request
import
re
class
myimagespipeline(imagespipeline):
def
get_media_requests(
self
, item, info):
for
image_url
in
item[
'imgurl'
]:
yield
request(image_url,meta
=
{
'item'
:item[
'name'
]})
def
file_path(
self
, request, response
=
none, info
=
none):
name
=
request.meta[
'item'
]
name
=
re.sub(r
'[?\\*|“<>:/()0123456789]'
, '', name)
image_guid
=
request.url.split(
'/'
)[
-
1
]
filename
=
u
'full/{0}/{1}'
.
format
(name, image_guid)
return
filename
def
item_completed(
self
, results, item, info):
image_path
=
[x[
'path'
]
for
ok, x
in
results
if
ok]
if
not
image_path:
raise
dropitem(
'item contains no images'
)
item[
'image_paths'
]
=
image_path
return
item
|
最后在settings.py中设置存储目录并开启通道:
1
2
3
4
5
6
|
# 设置图片存储路径
images_store
=
'f:/python/loldesk'
#启动pipeline中间件
item_pipelines
=
{
'loldesk.pipelines.myimagespipeline'
:
300
,
}
|
在根目录下运行程序:
1
|
scrapy crawl loldesk
|
大功告成!!!一共抓取到128个文件夹 。
希望本文所述对大家python程序设计有所帮助.
原文链接:https://blog.csdn.net/ziwoods/article/details/84321188 。
最后此篇关于Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】的文章就讲到这里了,如果你想了解更多关于Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
这显然有可能导致一场激烈的 war ,但无论如何,我试一试……(目前)还没有任何明确的答案。 在我的一台机器上,我确实被切换/升级到 Matlab 2012b。这是一个漂亮的新桌面,好吧。但出于很多原
当我的 Docker 容器启动时,我收到以下通知: Docker Desktop has detected that you shared a Windows file into a WSL 2 co
我希望能够(从服务器)连接到远程 PC 并能够访问其文件。我正在尝试使用 PHP 或 JavaScript 来完成此操作。 所以我想知道 1) 是否可能以及 2) 如何做到。 有人有任何示例/解决方案
我想使用 DirectX 为 Windows 7 制作动画桌面背景。我正在使用 C#、SlimDX 和几个 Windows API 函数的 P/Invoke 导入。我对 native Windows
是否可以为 Mac 开发动态桌面?我所说的“动态”是指其图像采用系统参数(例如时间和作业信息)并使用此信息来更新图像的桌面。有关图像状态的信息也将在 session 之间保留。我不是在谈论电影或随机但
我正在 LibGDX 中构建一个仅限桌面的应用程序。该游戏内置了一个 map 编辑器,您可以切换到并更改游戏 map 。我想添加一个功能,如果用户单击关闭窗口并且有未保存的编辑,它会提示您是否要在关闭
有没有像样的Windows桌面JSON lines (JSONL)格式查看器? 这种格式也称为: 行分隔的 JSON (LDJSON) 换行符分隔的 JSON (NDJSON) 我正在寻找至少能够从
我有一个UITableView,它在单元格中显示大量图像,并且我对滚动性能并不满意。我的 UITableView 类似于 iPhone 上的照片应用程序。有谁知道为什么 iphone 照片应用程序滚动
let img1 = document.createElement('img'); img1.setAttribute('src', 'https://caniuse.com/img/browsers
我在同一窗体上有两个不同的网格控件。它们共享相同的上下文菜单。当我选择上下文菜单项时,我无法确定哪个控件是所有者。 最佳答案 ContextMenuStrip 类的 SourceControl 属性将
我已经安装了 Docker Desktop ( version : 2.3.0.4 ) 并启用了 Kubernetes . 我部署了几个 PODS,一切正常,从昨天开始,我遇到了下面提到的一个奇怪的问
我正在制作需要实现TableView的应用程序。 我想将背景图像应用到桌面 View 。 谁能帮我解决这个问题。我正在使用下面的代码来创建 TableView Titanium.UI.setBackg
我在同一窗体上有两个不同的网格控件。它们共享相同的上下文菜单。当我选择上下文菜单项时,我无法确定哪个控件是所有者。 最佳答案 ContextMenuStrip 类的 SourceControl 属性将
您能建议一些库在我的桌面 Java 应用程序中创建雷达图吗? 谢谢 最佳答案 似乎JFreeChart提供了SpiderWebPlot 。 images for which看起来像雷达图。 关于jav
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Not possible to launch a file on a network using Java Desk
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我想知道是否可以(使用JAVA)识别用于发出请求的计算机类型,例如:服务器、台式机、PDA(平板电脑、手机等)? 谢谢! 最佳答案 取决于您使用什么来接受请求。对于 http 请求,信息位于请求 he
我添加了一个事件处理程序,用于滚动到我的桌面 View ,但它仅在我使用滚轮滚动时才起作用,但我也需要它在您单击并拖动滚动条时起作用。任何想法有什么问题吗?我尝试使用不同的方法来处理该事件,但没有一个
我想开始开发桌面 Java 应用程序,并且我想知道 Java 社区使用什么。 我从 Swing 开始,但发现它非常初级。 我习惯于在 Visual Studio 2010 中使用 .net c# WP
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我是一名优秀的程序员,十分优秀!