关于网页图片的爬取

在今日头条搜索了Eason的图片,今日头条和移动版微博(m.weibo.cn)是一样的,请求是ajax,通过爬取ajax内容来取到图片的路径,然后爬取图片路径的内容:

  1. import urllib.request
    aurl = ‘https://p9-tt.bytecdn.cn/list/pgc-image/R9qC8pCGt9XDtp’ #图片链接
    urllib.request.urlretrieve(aurl,r’D:\python\notebook\ajax\toutiao\yixun.png’) # 把图片链接获取到的二进制内容保存到这个路径下。

import requests
response = requests.get(‘https://p9-tt.bytecdn.cn/list/pgc-image/R9qC8pCGt9XDtp’)
with open(r’D:\python\notebook\ajax\toutiao\yixun.png’,‘wb’) as fp: #wb是写入bytes内容
fp.write(response.content)

猜你喜欢

转载自blog.csdn.net/miaokezhang/article/details/84330281