python获取图片url链接后保存到本地
#!/usr/bin/env python# -*- coding:utf-8 -*-import jsonimport timeimport requestsimport urllib.requesturl = 'http://manage.w.rongyi.com/ops/cmd/queryRecord'headers = {"Content-Type":"appli...
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
import time
import requests
import urllib.request
url = 'http://manage.w.rongyi.com/ops/cmd/queryRecord'
headers = {
"Content-Type":"application/json;charset=UTF-8",
"Cookie":"RYST=866a6b1a589c6f07d72574d1aa368857",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER"
}
i = 9912842
for k in range(0,10): #循环10次
requests.post(url="http://manage.w.rongyi.com/ops/cmd/screenShot", headers=headers, json={"machineIdList":[13010]})
time.sleep(30)
data = {"controlIdList": [i]} # 根据machineIDList生成规律进行参数化,每次+1
response = requests.post(url=url, headers=headers, json=data)
data = json.loads(response.content)
print(response.content)
# created_id = re.findall(r'"id":(.+?),"', r.text) # 正则匹配新建的id
# ops_photos = re.findall(r'{"url":"(.+?)"}',response.text)
ops_photos = data['result']['data'][0]['data']['url'] #获取图片位置
# ops_img = str(ops_photos)
# file_name = 'D:/youyoutest/lining'
# with open(file_name,'wb') as img_ops:
# lib = urllib.request.urlretrieve(ops_photos,'D:/3.jpg')
urllib.request.urlretrieve(ops_photos, 'D:/youyoutest/lining/ops_imgs'+ str(k) +'.jpg')
i = i + 1
更多推荐
所有评论(0)