Skip to content

Commit b9d9dda

Browse files
committed
add 0013
1 parent c1160e3 commit b9d9dda

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎Jaccorot/0013/0013.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/python
2+
# coding=utf-8
3+
4+
"""
5+
第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-)
6+
"""
7+
8+
import os
9+
import urllib
10+
from bs4 import BeautifulSoup
11+
from urlparse import urlsplit
12+
13+
14+
def catch_tieba_pics(url):
15+
content = urllib.urlopen(url)
16+
bs = BeautifulSoup(content, 'lxml')
17+
for i in bs.find_all('img', {"class": "BDE_Image"}):
18+
download_pic(i['src'])
19+
20+
21+
def download_pic(url):
22+
image_content = urllib.urlopen(url).read()
23+
file_name = os.path.basename(urlsplit(url)[2])
24+
output = open(file_name, 'wb')
25+
output.write(image_content)
26+
output.close()
27+
28+
29+
if __name__ == '__main__':
30+
catch_tieba_pics('http://tieba.baidu.com/p/2166231880')

0 commit comments

Comments
 (0)