想实现桌面图标的移动,可是不知道怎么获取桌面图标的坐标(x,y),需要python实现
桌面本质上是一个listview32,可以发消息得到每个图标的坐标
import requests # 数据请求模块 第三方模块 pip install requests 安装好之后没有使用模块 灰色显示
import parsel # 数据解析模块 第三方模块 pip install parsel
import re # 正则表达式 内置模块 不需要安装
# 1. 发送请求
# 需要注意点: 确定请求url地址 请求方法 请求头参数(某些网站需要加cookie 或者 防盗链)
for page in range(12, 21):
print(f'正在爬取第{page}页数据内容')
url = f'https://fabiaoqing.com/biaoqing/lists/page/{page}.html'
# headers 作用伪装python代码的 爬虫是模拟浏览器对于服务器发送请求
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
# 2. 获取数据, 获取服务器返回的数据内容(response响应体数据) response.text 获取响应体文本数据
# 3. 解析数据 提取内容, 是要根据服务器返回的数据, 而不是看元素面板
# print(response.text) # 得到的response.text 这个html字符串数据 直接提取字符串数据内容 需要用re正则表达式
selector = parsel.Selector(response.text) # 把得到的字符串数据内容 转换成 selector 对象
# css选择器 就是根据标签属性内容提取数据
divs = selector.css('div.ui.segment.imghover div') # 获取所有div标签 返回对象
for index in divs:
# a::attr(title) 获取a标签里面 title 属性 数据 get() 获取第一个标签数据内容
title = index.css('a::attr(title)').get()
title = re.sub(r'[\/:*?"<>|\n]', '', title)
img_url = index.css('img::attr(data-original)').get()
# split 字符串分割的方法 列表[-1] 取最后一个元素 右边的第一个元素
img_name = img_url.split('.')[-1]
# response.content 获取二进制数据内容, 保存图片/视频/音频/特定格式的文件内容 都是以二进制数据保存
img_content = requests.get(url=img_url, headers=headers).content
with open('img\\' + title + '.' + img_name, mode='wb') as f:
f.write(img_content)
print(title, '保存成功')