Skip to content

Commit

Permalink
the third commitment
Browse files Browse the repository at this point in the history
  • Loading branch information
Silocean committed Jun 6, 2015
1 parent f5b887e commit e9e9c04
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
Binary file removed Silocean/0000/icon.jpg
Binary file not shown.
Binary file removed Silocean/0000/result.jpg
Binary file not shown.
39 changes: 39 additions & 0 deletions Silocean/0007/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
__author__ = 'Tracy'

import os, io, re

commentLines = 0
whiteLines = 0
comment = False

path = 'F:\AllKindsOfWorkplace\PyCharmWorkplace\PythonLearning'

count = 0
def tree(path):
filelist = os.listdir(path)
for file in filelist:
if os.path.isdir(os.path.join(path, file)):
tree(os.path.join(path, file))
else:
filename = os.path.basename(os.path.join(path, file))
if filename.endswith(".py"):
# print(filename)
file = io.open(os.path.join(path, file))
parse(file)
file.close()

def parse(file):
global commentLines
global whiteLines
global comment
for line in file.readlines():
# line = line.strip("\n")
if line.startswith("#"):
commentLines += 1
elif re.match("^[\\s&&[^\\n]]*$", line):
whiteLines += 1

tree(path)

print(commentLines)
print(whiteLines)
17 changes: 17 additions & 0 deletions Silocean/0008/Test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This is the Title</title>

</head>
<body>
<div id="container">

<div id="nav">

<div style="display:none">
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9394293" charset="UTF-8"></script>
</div>
</body>
</html>
11 changes: 11 additions & 0 deletions Silocean/0008/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# -*- coding=utf-8 -*-

from bs4 import BeautifulSoup
import io
file = io.open('Test.html', 'r')
soup = BeautifulSoup(file)
print(soup.getText().strip("\n"))


file.close()
19 changes: 19 additions & 0 deletions Silocean/0009/Test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<link rel="stylesheet" href="http://tb1.bdstatic.com/??/tb/_/thread_recommend_50cc234.css,/tb/_/grade_e31ce1c.css,/tb/_/interest_smiley_90ea01d.css,/tb/_/aside_float_bar_b8d73a2.css" />
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a>
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>
and they lived at the bottom of a well.</p>
<img pic_type="0" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=527796ed1f178a82ce3c7fa8c603737f/d3af6ccb0a46f21f6e583272f7246b600c33ae0c.jpg" bdwater="shanshanyoumei,1280,860" width="560" height="376" changedsize="true">
<p class="story">...</p>
</body>
</html>
21 changes: 21 additions & 0 deletions Silocean/0009/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
__author__ = 'Tracy'

from bs4 import BeautifulSoup
import io

with io.open('Test.html') as file:
html = file.read()
soup = BeautifulSoup(html)
listA = soup.find_all('a')
listL = soup.find_all('link')
listI = soup.find_all('img')
# print(listA)
# print(listL)
# print(listI)

for x in listA:
print(x['href'])
for x in listL:
print(x['href'])
for x in listI:
print(x['src'])
21 changes: 21 additions & 0 deletions Silocean/0013/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
__author__ = 'Tracy'
from urllib import urlopen
from bs4 import BeautifulSoup

f = urlopen('http://tieba.baidu.com/p/2166231880').read()

s = BeautifulSoup(f)

images = s.find_all('img', pic_type='0')
count = 1
def download(src):
global count
file_name = str(count) + '.jpg'
content = urlopen(src).read()
with open(file_name, 'wb') as f:
f.write(content)
count += 1

for image in images:
download(image['src'])

0 comments on commit e9e9c04

Please sign in to comment.