python3爬虫get请求

python3

encoding(‘utf-8’)

导入

import urllib.request

get请求 读取html内容

f=urllib.request.urlopen(‘http://jingyan.baidu.com/article/455a9950bc94b8a166277898.html‘)
response=f.read()
print(‘—–response——’)
print(str(response))
print(f.geturl())
print(f.getcode())

读取图片并保存

urllib.request.urlretrieve(‘http://hiphotos.baidu.com/exp/pic/item/5beeba0f4bfbfbed25bd434d7ff0f736aec31fd8.jpg‘)

将图片保存到固定位置

urllib.request.urlretrieve(‘http://hiphotos.baidu.com/exp/pic/item/5beeba0f4bfbfbed25bd434d7ff0f736aec31fd8.jpg‘,filename=’E:/a.png’)

    原文作者:android-李志强
    原文地址: https://blog.csdn.net/lzq520210/article/details/76853445
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞