# -*-coding:utf8-*-
from bs4 import BeautifulSoup
import requests
url="https://pic.netbian.com/"
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",
"Cookie":"__yjs_duid=1_2a164cf046be81d7beb2763bc6cb93b61630917990494; Hm_lvt_14b14198b6e26157b7eba06b390ab763=1630918037,1630918351,1632497782; Hm_lpvt_14b14198b6e26157b7eba06b390ab763=1632497866; Hm_lvt_526caf4e20c21f06a4e9209712d6a20e=1630917991,1630918105,1630918106,1632498677; Hm_lpvt_526caf4e20c21f06a4e9209712d6a20e=1632501219"}
response=requests.get(url,headers=headers)
response1=BeautifulSoup(response.text,"html.parser")
response2=response1.find("ul",attrs={"class":"clearfix"}).find_all("a",attrs={"target":"_blank"})
for i in response2:
href=("https://pic.netbian.com"+str(i.get('href')))
res1=requests.get(href)
res1.encoding='gbk'
childpage=BeautifulSoup(res1.text,"html.parser")
img1=childpage.find("div",attrs={"class":"photo-pic"}).find("a",attrs={"id":"img"}).find("img").get("src")
src="https://pic.netbian.com/"+str(img1)
f=open("壁纸%s.jpg",mode="wb")
f.write(requests.get(src).content)
求位巨佬..我的只能爬取第一页的某一张壁纸而不是第一页的所有 如何解决
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 江天暮雪丨 2021-09-25 09:17关注
逐步调试呀。
f=open("壁纸%s.jpg",mode="wb") f.write(requests.get(src).content)
%s 你是想输出什么呢?你一直都是在打开 ”壁纸%s.jpg“ 这个文件进行操作,当然最后只有一个图片,被后面的图片覆盖掉了
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 软件测试决策法疑问求解答
- ¥15 win11 23H2删除推荐的项目,支持注册表等
- ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
- ¥15 qt6.6.3 基于百度云的语音识别 不会改
- ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
- ¥15 神经网络怎么把隐含层变量融合到损失函数中?
- ¥15 lingo18勾选global solver求解使用的算法
- ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
- ¥20 测距传感器数据手册i2c
- ¥15 RPA正常跑,cmd输入cookies跑不出来