当前位置:   article > 正文

python 爬取阴阳师图片

python 爬取阴阳师图片
import requests
from lxml import etree
import threading
import time
import os
def get_url(url):
    header={"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54"}
    req=requests.get(url, headers=header)
    return req
def get_picture(req):
    e=etree.HTML(req.text)
    urls=e.xpath("//div[@class='tab-cont']/div/div/img/@data-src")
    urls=[url.replace("1366x768", "2732x2048") for url in urls]
    urls=[url.replace("640x960", "1080x1920") for url in urls]
    urls=[url.replace("1024x768", "2732x2048") for url in urls]
    return urls
def download_picture(url):
    name="python\\picture\\图片\\"+url[62:70]+'_'+url[71:72]+'.jpg'
    pic=get_url(url).content
    # time.sleep(1)
    print(f"Downloading picture {name}")
    with open(f"{name}",'wb') as f:
        f.write(pic)
def make_directory():
    if not os.path.exists("python\picture\图片"):
        os.makedirs("python/picture/图片")
     
make_directory()
req=get_url("https://yys.163.com/media/picture.html")
urls=get_picture(req)
# print(urls)
for url in urls:
    download_picture(url)
  • 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
  • 32
  • 33

ps: 技术无罪

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/490043
推荐阅读
相关标签
  

闽ICP备14008679号