You can copy the address on the page picture right
most of the site has anti-climb mechanism, not easy to find a can climb
Program can not climb the encounter site is run successfully, the output status codes and error messages is a good habit
text Returns the text
json return object
content is returned in the form of a binary picture data
# -*- coding: utf-8 -*-
import requests
if __name__ == '__main__':
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36'
}
url = 'https://t1.hddhhn.com/uploads/tu/201702/54/st1.png'
#content返回的是二进制形式的图片数据
img_data= requests.get(url=url,headers=headers)
# 输出状态码
print(img_data.status_code)
# 输出错误
print(img_data.raise_for_status())
with open('./mmt.jpg','wb') as fp:
fp.write(img_data.content)