马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
使用方法,需要在同级目录建立一个pics的文件夹,同时需要安装库grequests。
grequests安装方法如下:
在CMD中输入以下命令:
pip install grequests
话不多说,直接上代码:
import grequests
from pyquery import PyQuery
import pathlib
name = 1
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0"
}
for i in range(0, 226, 25):
urls = f"https://movie.douban.com/top250?start={i}&filter="
# print(urls)
response = grequests.get(urls,headers=headers),
get_ = grequests.map(response)
contentt = get_[0].text
# print(contentt)
pyq = PyQuery(contentt)
cc = pyq.find("img").items()
for j in cc:
# print(j.attr("src"))
src_urls = j.attr("src")
# print(src_urls)
res = grequests.get(src_urls),
resss = grequests.map(res)
cont = resss[0].content
path = pathlib.Path(f"pics/{name}.jpg")
path.write_bytes(cont)
name = name + 1
|