SDUWH2019-2020寒假python实训--Chp4.2

import requests_html

#先创建一个会话session对象,做访问等操作
sess = requests_html.HTMLSession()
#通过对象的实例sess访问
word='李小龙'
url=f'http://image.baidu.com/search/index?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&word={word}'
resp = sess.get(url)
print(resp,type(resp))#<Response [200]> <class 'requests_html.HTMLResponse'>
# requests_html.HTMLResponse
# print('text:',resp.text)
print('content:',resp.content)
# print('html:',resp.html)#html: <HTML url='https://www.baidu.com/'>

#查询我需要下载的图片的地址
reg='"thumbURL":"{}"'
addr_list=resp.html.search_all(reg)
print(addr_list)
for i in addr_list:
    print(i[0])
# img_url = 'http://img1.imgtn.bdimg.com/it/u=1257999503,335128034&fm=26&gp=0.jpg'
# resp_img = sess.get(img_url)
# with open('1.jpg','wb') as f:
#     f.write(resp_img.content)
SDUWH2019-2020寒假python实训--Chp4.2SDUWH2019-2020寒假python实训--Chp4.2 KingoKing 发布了14 篇原创文章 · 获赞 0 · 访问量 117 私信 关注
上一篇:Hello World.


下一篇:Tensorflow