forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) | ||
|