文章目录

利用python的requests模块下载百度贴吧图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup

url = 'http://tieba.baidu.com/p/4468445702'
html = requests.get(url)
html.encoding = 'utf-8'
text = html.text

bsop = BeautifulSoup(text,'html.parser')
img_list = bsop.find('div',{'id':'post_content_87286618651'}).findAll('img')
img_src = img_list[0].attrs['src']

print(img_src)
img = requests.get(img_src)
with open('1.jpg', 'ab') as f:
f.write(img.content)
f.close()
文章目录
Fork me on GitHub