Skip to content

Commit 3c5744d

Browse files
author
bin jim
committed
second commit
1 parent 1a2be3e commit 3c5744d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

requests1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
import requests
3+
from bs4 import BeautifulSoup
4+
5+
6+
url = 'http://tieba.baidu.com/p/4468445702'
7+
html = requests.get(url)
8+
html.encoding = 'utf-8'
9+
10+
text = html.text
11+
bsop = BeautifulSoup(text,'html.parser')
12+
img_list = bsop.find('div',{'id':'post_content_87286618651'}).findAll('img')
13+
img_src = img_list[0].attrs['src']
14+
15+
print(img_src)
16+
img = requests.get(img_src)
17+
with open('a.jpg', 'ab') as f:
18+
f.write(img.content)
19+
f.close()
20+
21+
22+
# content = html.content
23+
# print(text)
24+
# print(content)

0 commit comments

Comments
 (0)