其他分享
首页 > 其他分享> > 获取极客学院职业方向图片

获取极客学院职业方向图片

作者:互联网

import requests
import re  

#1请求数据
URL = 'https://www.jikexueyuan.com'      ## 目标网址
headers = {"User-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"}
#2伪装头
res = requests.get(URL,headers=headers)
#3发送 GET 方式的请求,并把返回的结果(响应)存储在 res 变量里头
html = res.text
#4获取图片地址
i = 0
pic_url = re.findall('src="(http://jiuye-res.jikexueyuan.com/zhiye.*?)"',html)   # src="(.*.png)"
for each in pic_url:
    print('now doanloading:' + each)
    pic = requests.get(each,headers=headers) 
    sjpg = open('VScode/pic/'+ str(i) + '.jpg' ,'wb')      #windows路径写法 VScode\\pic\\
    sjpg.write(pic.content)
    sjpg.close
    i += 1

标签:极客,headers,res,pic,获取,each,sjpg,requests,职业
来源: https://www.cnblogs.com/Ryan2019/p/16559992.html