Skip to content

Commit 5296e3b

Browse files
committed
Merge pull request Show-Me-the-Code#21 from renzongxian/master
Add the solution to 0009
2 parents 3d83489 + 4d0b5d5 commit 5296e3b

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

renzongxian/0000/0000.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def add_num_to_img(file_path):
1919
font = ImageFont.truetype("arial.ttf", int(im.size[0]/5))
2020
im_draw.text((int(im.size[0]-im.size[0]/10), 5), "4", (256, 0, 0), font=font)
2121
del im_draw
22-
im.save(file_path)
22+
im.save('./result.png')
2323

2424
if __name__ == "__main__":
2525
if len(sys.argv) <= 1:
@@ -32,3 +32,4 @@ def add_num_to_img(file_path):
3232
except IOError:
3333
print("Can't open image!")
3434
pass
35+

renzongxian/0008/0008.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+
# Author:renzongxian
3+
# Date:2014-12-20
4+
# Python 3.4
5+
6+
"""
7+
8+
第 0008 题:一个HTML文件,找出里面的正文。
9+
10+
"""
11+
12+
import urllib.request
13+
import re
14+
15+
16+
def get_body(url):
17+
html_content = urllib.request.urlopen(url).read()
18+
r = re.compile('<p>(?:<.[^>]*>)?(.*?)(?:<.[^>]*>)?</p>')
19+
result = r.findall(html_content.decode('GBK'))
20+
return result
21+
22+
23+
if __name__ == '__main__':
24+
body = get_body('http://tech.163.com/14/1219/01/ADPT7MTE000915BF.html')
25+
file_object = open('result.txt', 'w')
26+
for l in body:
27+
file_object.write(l + '\n')
28+
file_object.close()
29+

renzongxian/0009/0009.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
2+
# Author:renzongxian
3+
# Date:2014-12-19
4+
# Python 3.4
5+
6+
"""
7+
8+
第 0009 题:一个HTML文件,找出里面的链接。
9+
10+
"""
11+
12+
import urllib.request
13+
import re
14+
15+
16+
def find_links(website):
17+
html_content = urllib.request.urlopen(website).read()
18+
r = re.compile('href="(.*?)"')
19+
result = r.findall(html_content.decode('GBK'))
20+
return result
21+
22+
if __name__ == '__main__':
23+
print(find_links('http://www.taobao.com/'))

0 commit comments

Comments
 (0)