網上很多代碼都不適用於python3版本,所以還是轉回版本2來學習了
install 安裝模組特別簡單 E:\01_SOFT\Python27\python -m easy_install sunburnt
E:\01_SOFT\Python27\python -m easy_install lxml
E:\01_SOFT\Python27\python -m easy_install requests
Microsoft Visual C++ Compiler for Python 2.7
http://www.microsoft.com/en-us/download/confirmation.aspx?id=44266
beautifulsoup4
cd E:\01_SOFT\beautifulsoup4-4.3.2\beautifulsoup4-4.3.2
python setup.py install
mongodb安裝
http://blog.csdn.net/t_ells/article/details/50265889
E:\01_SOFT\mongodb\mongodb-win32-x86_64-2.2.0\bin\mongod --dbpath "E:\01_SOFT\mongodb\data"
pymongo
https://pypi.python.org/pypi/pymongo/
安裝$ E:\01_SOFT\Python27\python -m easy_install pymongo
download
https://www.python.org/downloads/release/python-352/
python實現簡單爬蟲功能
http://www.cnblogs.com/fnng/p/3576154.html
Python類比百度登入執行個體詳解
http://www.jb51.net/article/78406.htm
時間戳記轉換工具
http://tool.lu/timestamp
使用Python解析JSON資料的基本方法
http://www.jb51.net/article/73450.htm
Unicode編碼轉換
http://tool.chinaz.com/tools/unicode.aspx
Json線上解析
http://www.bejson.com/jsonviewernew/
軟體下載
https://pan.baidu.com/share/home?uk=2466540631#category/type=0
Python爬蟲入門六之Cookie的使用
http://cuiqingcai.com/968.html
Cookies and CookieJar
https://bytes.com/topic/python/answers/802534-cookies-cookiejar
Python實戰計劃學習作業2-1
http://blog.csdn.net/python012/article/details/53344501
1.關於api-ms-win-crt-runtimel1-1-0.dll缺失的解決方案
https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=48145
2.can't use a string pattern on a bytes-like object
imglist = re.findall(imgre,html.decode('GBK'))
3.inconsistent use of tabs and space in indentation
把tab替換成空格
4.UnicodeDecodeError:'gbk' codec can't decode byte 0xaf in position 197:illegal multibyte sequence
html.decode('utf-8')
5.Missing parentheses in call to 'print'
print x
改成print(x)
6.IndentationError:expected an indented block錯誤解決
print前面空格不同代表不同層次
對縮排非常敏感,有冒號的下一行往往要縮排,該縮排就縮排
7.Python EOL while scanning string literal問題解決方案
引號沒有成對出現
8.Beautifulsoup BS4
https://pypi.python.org/pypi/beautifulsoup4/4.3.2
cd E:\01_SOFT\beautifulsoup4-4.3.2\beautifulsoup4-4.3.2
python setup.py install
soup = BeautifulSoup(open('index.html'))
print soup.prettify()
list = soup.findAll('a');
list = soup.findAll(name='a',href=re.compile(r"kw=")) ;
list = soup.findAll(name='a',attrs={'href':re.compile(r"kw="),'title':re.compile(r".")}) ;
9.儲存網頁,百度的不成功
import urllib
def cbk(a, b, c):
'''回呼函數
@a: 已經下載的資料區塊
@b: 資料區塊的大小
@c: 遠程檔案的大小
'''
per = 100.0 * a * b / c
if per > 100:
per = 100
print '%.2f%%' % per
urllib.urlretrieve('http://www.cmfish.com/bbs/forum.php','D:\\06_Download\\py\\baidu1.html',cbk);
10.儲存字串
def save(filename, contents):
fh = open(filename, 'w')
fh.write(contents)
fh.close()
save('D:\\06_Download\\py\\baidu.html', content)
11.UnicodeEncodeError: ‘gbk‘ codec can‘t encode character u‘\xa9‘ in position 24051: illegal multibyte sequence
source_code.encode(‘GB18030‘)
not work!
12.TypeError: coercing to Unicode: need string or buffer, type found
??
13.'ascii' codec can't encode characters in position 4-7:ordinal not in range(128)
str('中文')???
14.invalid mode('w') or filename
檔案路徑錯誤
f = file("E:\json.txt",'w')
改成
f = file("E:\\json.txt",'w')
15. No JSON object could be decoded
expected string or buffe
pythod invalid file mode or filename
>將檔案儲存為不帶BOM的UTF-8格式
import json
from pymongo import MongoClient
client = MongoClient('127.0.0.1', 27017)
db = client["Collections"]#資料庫名
table=db['user']#表名
table.insert({'id':'1','name':'cnki'})
f = file("D:\\json.txt")
j = json.loads(f.read());
table=db['jsontxt']#表名
courseId = table.save(j)
Python中解析Json檔案出錯:ValueError : No JSON object could be decoded –> Python中Json庫不支援帶BOM的UTF-8
http://www.crifan.com/fixed_problem_for_python_valueerror_no_json_object_could_be_decoded/
16.Non-ASCII character '\xe5' in file ……
原因:Python預設是以ASCII作為編碼方式的,如果在自己的Python源碼中包含了中文(或者其他非英語系的語言),此時即使你把自己編寫的Python源檔案以UTF-8格式儲存了,但實際上,這依然是不行的。
需要在檔案前面加 #coding=utf-8
17.unexpected unident
空格或tab鍵對齊