可简单爬取知乎上当前网页的图片,直接负责网址到url处,修改i的值即可(保存路径稍微改改)

import requests
import re
import time


def spider(url, headers):

response = requests.get(url, headers=headers)
pat1 = re.compile(r‘<noscript><img src="(.*?)"‘, re.S)
url_list = pat1.findall(response.text)
i = 64 # 待修改,修改i的值可给爬到的图片命名
for url in url_list:
result = requests.get(url, headers)
with open(fr"C:\Users\marginal\Desktop\壁纸\{i}.jpg", "wb") as f:
f.write(result.content)
print(f"正在下载第{i}张图片")
time.sleep(0.5)
i += 1
print("over")


def main():
url = r‘https://zhuanlan.zhihu.com/p/164538508‘ # 待修改,给知乎上有图片的网站就能爬
headers = {‘user-agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ‘
‘Chrome/89.0.4389.114 Safari/537.36‘,
}
spider(url, headers)


if __name__ == ‘__main__‘:
main()



可简单爬取知乎上当前网页的图片,直接负责网址到url处,修改i的值即可(保存路径稍微改改)

上一篇:Ubuntu20.04 安装 .NET Core SDK


下一篇:web操作摄像头、高拍仪、指纹仪等设备的功能扩展方案