日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python_summary

發(fā)布時間:2025/3/20 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python_summary 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Q: python中出現(xiàn)IndentationError:unindent does not match any outer indentation level
A:復(fù)制代碼的時候容易出現(xiàn)縮進(jìn)錯誤,雖然看起來是縮進(jìn)了,但是實際上沒有。可以用Notepad++下的
? ? ?視圖->顯示符號->顯示空格和制表符 來觀察是否縮進(jìn)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~簡單爬蟲python2.7~~~~~~~~~~~~~~~~~~~~~~~~~~

''' 簡單爬蟲 ''' #encoding:utf-8import urllib import sys import re#設(shè)置編碼 reload(sys) sys.setdefaultencoding('utf-8') #獲取系統(tǒng)編碼格式 type = sys.getfilesystemencoding() def getHtml(url):page = urllib.urlopen(url)html = page.read().decode('utf-8').encode(type)return htmldef cbk(a,b,c):'''a:已經(jīng)下載的數(shù)據(jù)塊b:數(shù)據(jù)塊的大小c:遠(yuǎn)程文件的大小'''per = 100.0*a*b/cif per > 100 :per = 100print '%.2f%%' %per def getImg(html):reg = r'src="(.+?\.jpg)" alt' imgre = re.compile(reg)imglist = re.findall(imgre,html)#x = 0for img in imglist:local = 'c://Users/xujianjun/Desktop/python/x.jpg' #不能只包含路徑,必須是路徑+文件名urllib.urlretrieve(img,local,cbk) #回調(diào)函數(shù)定義必須有三個參數(shù),哪怕不需要#x += 1return imglist html = getHtml("http://www.cnblogs.com/1023linlin/p/8525273.html") print getImg(html)

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

?

轉(zhuǎn)載于:https://www.cnblogs.com/1023linlin/p/8648499.html

總結(jié)

以上是生活随笔為你收集整理的Python_summary的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。