python爬虫——requests

python爬虫requests上

3.用urlretrieve:

python爬虫——requests_第1张图片

2.with open

import urllib.request
import urllib.parse
import requests
url ='https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=python%20%E5%9C%A8%E5%BA%93%E9%87%8C%E9%9D%A2%E5%AE%89%E8%A3%85json&step_word=&hs=0&pn=0&spn=0&di=3200&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=3292127761%2C2561460082&os=1102035953%2C4035766811&simid=0%2C0&adpicid=0&lpn=0&ln=1195&fr=&fmq=1618834820344_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined©right=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=15&oriquery=&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%3A%2F%2Fimg-blog.csdnimg.cn%2F20200526170234488.png%3Fx-oss-process%3Dimage%2Fwatermark%2Ctype_ZmFuZ3poZW5naGVpdGk%2Cshadow_10%2Ctext_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3ZpY3RvcnkwOTQz%2Csize_16%2Ccolor_FFFFFF%2Ct_70%26refer%3Dhttp%3A%2F%2Fimg-blog.csdnimg.cn%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Djpeg%3Fsec%3D1621426988%26t%3D12927a841d449e0a8c00666fac19a8cb&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bvf1g_z%26e3BgjpAzdH3F2wpij6_dcAzdH3FMpTwM2afNDvyM3QpY4xeZoOaOaOOaOaO_z%26e3Bip4s&gsm=1&rpstart=0&rpnum=0&islist=&querylist=&force=undefined'
res =requests.get(url)
# fn =open('code.png','wb')
# fn.write(res.content)
# fn.close()
with open('code2.jpg','wb') as f:
    f.write(res.content)

python爬虫——requests_第2张图片

方法三:urlretrieve

python爬虫——requests_第3张图片

1.urllib——基础图片的爬取

python爬虫——requests_第4张图片

python爬虫——requests_第5张图片
python爬虫——requests_第6张图片
python爬虫——requests_第7张图片

urlib.request的使用

字节流数据转换——字节→str类型——bytes

python爬虫——requests_第8张图片

python爬虫——requests_第9张图片

你可能感兴趣的:(python爬虫笔记,python)