zhangjun0204

女朋友接到了个任务,就是把N多张图片挨个上传到公司网站上,她自己搞了半天进度缓慢,然后就打起我的主意来了。像我这么懒的人,当然是懒得动了,但是自己的女朋友,必须宠着。
需求大概是这样:把图片上传到公司网站后台,然后给图片命名,就完事了。
几小时的工作,几分钟搞定。

# -*-coding:utf-8 -*-

import requests
from requests import exceptions
import re
import  time
import os


def getHtml(name,path):
    files = {'image': (name, open(path, 'rb'))}
    #定义请求头 伪装成浏览器 添加 cookie
    headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',"Cookie": "PHPSESSID=1v0uo************"}
    try:
        r=requests.post('https://www.XXXX.com/admin_picture/',data={'name':name+" wx"},files=files,headers=headers)
        r.raise_for_status()
        r.encoding=r.apparent_encoding
        return r.text
    except requests.RequestException as e:
        return e.strerror

def getfile():
    for  filenames in os.walk("C:\\Users\\Documents\\WeChat Files\\zj19950204\\FileStorage\\File\\2020-03\\wx\\wx"):  
        for i in filenames:
            #print(i.split('.')[0])
            getHtml(i.split('.')[0],"C:\\Users\\Documents\\WeChat Files\\zj19950204\\FileStorage\\File\\2020-03\\wx\\wx\\"+i)
            #停顿一下,避免服务器崩掉
            time.sleep(2)

getfile()

分类:

技术点:

相关文章:

  • 2021-11-11
  • 2021-12-31
  • 2021-06-28
  • 2021-08-11
  • 2021-11-16
  • 2021-10-14
  • 2021-07-02
猜你喜欢
  • 2021-06-13
  • 2022-03-07
  • 2022-02-12
  • 2021-09-02
  • 2020-02-06
  • 2021-10-27
相关资源
相似解决方案