A. python爬取圖片時忽略了一些圖片
真實圖片地址是在客戶端javascript代碼中計算出來的.
你需要尋找
<spanclass="img-hash">tnaS5qcGc=</span>
這樣的內容,取出
tnaS5qcGc=
這段內容,做base64解碼即得圖片地址。
相應的腳本在
//cdn.jandan.net/static/min/.03100001.js
這段內容你通過get_page()爬到地頁面中有,同樣,該頁面中有這樣的html(為便於閱讀已重排格式):
<divclass="text">
<spanclass="righttext">
<ahref="//jandan.net/ooxx/page-34#comment-4001800">4001800</a>
</span>
<p>
<imgsrc="//img.jandan.net/img/blank.gif"onload="jandan_load_img(this)"/>
<spanclass="img-hash">tnaS5qcGc=</span>
</p>
</div>
這個img的onload調用的函數就在前面給出的那個js文件中:
functionjandan_load_img(b){
vard=$(b);
varf=d.next("span.img-hash");
vare=f.text();
f.remove();
varc=(e,"");
vara=$('<ahref="'+c.replace(/(//w+.sinaimg.cn/)(w+)(/.+.(gif|jpg|jpeg))/,"$1large$3")+
'"target="_blank"class="view_img_link">[查看原圖]</a>');
d.before(a);
d.before("<br>");
d.removeAttr("onload");
d.attr("src",location.protocol+c.replace(/(//w+.sinaimg.cn/)(w+)(/.+.gif)/,"$1thumb180$3"));
if(/.gif$/.test(c)){
d.attr("org_src",location.protocol+c);
b.onload=function(){
add_img_loading_mask(this,load_sina_gif)
}
}
它調用了對img-hash的內容做解碼,這個函數同樣在這個js文件中:
var=function(o,y,g){
vard=o;varl="DECODE";
vary=y?y:"";
varg=g?g:0;
varh=4;
y=md5(y);
varx=md5(y.substr(0,16));
varv=md5(y.substr(16,16));
...中間部分略去...
if(l=="DECODE"){
m=base64_encode(m);
varc=newRegExp("=","g");
m=m.replace(c,"");
m=u+m;
m=base64_decode(d)
}
returnm
};
你只需要在Python使用相應的庫對抓取到的img-hash內容做解碼即可得到圖片地址。
你使用了str的find來從文本中定位位置,這樣做太麻煩了,太多的代碼細節,使用re模塊做正則匹配就簡單很多,更快的是直接使用現有的爬蟲庫.
使用re進行正則匹配,只需要使用正則式'<spanclass="img-hash">(.+?)<'即可提取出該頁面中所有加密的圖片地址。
importre
importbase64
pat=re.compile('<spanclass="img-hash">(.+?)<')
...
defget_imgurls(url):
urls=[]
forimgurlinpat.findall(url_open(url).decode('utf-8')):
.append(str(base64.b64decode(imgurl),'utf-8'))
returnurls
然後就可以對get_imgurls返回的列表遍歷,逐個交給save_img處理了。
使用爬取庫也只需要尋找span,從中找出class='img-hash'即可讀取text。
B. 求推薦筆記本電腦
可以看看華碩的天選系列,無畏系列。
目前華碩商城與有得賣網合作推出」以舊換新服務」(品牌不限),回收舊機兌換華碩商城代金券與現金,代金券用於華碩商城購買商品的服務。
官方商城登錄方式如下:
在華碩官網首頁主菜單找到「華碩官方商城」,進入「以舊換新」。在頁面輸入產品信息,即會有估價信息。
C. python 通過pip安裝matplotlib報錯
PermissionError: [Errno 13] Permission denied: 'C:\Users\ADMINI~1\AppData\Lo cal\Temp\pip-build-a4z3oo5u\matplotlib\matplotlib/concrt140.dll' 訪問許可權的問題吧, 管理員身份運行終端, 重新執行一次試試
D. Python3.6.0安裝Matplotlib總是出現如下的錯誤 numpy啥的都裝成功了:求大神幫忙
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\ADMINI~1\\AppData\\Lo
cal\\Temp\\pip-build-a4z3oo5u\\matplotlib\\matplotlib/concrt140.dll'
訪問許可權的問題吧, 管理員身份運行終端, 重新執行一次試試
E. python教程哪裡下載
一、Python入門到進階的 廖雪峰 Python & JS & Git 教程PDF版 鏈接:F. 求看python 統計中文詞頻的代碼,有一個地方不懂 求大神
首先要說明一個概念:gbk編碼里一個中文字元的『長度』是2。
str='中國'#gbk編碼
要取得'中'這個字元,需要用分片str[0:2],而不是索引str[0]。
以z4為例,下面這些代碼的效果是這樣的。
x='同舟共濟與時俱進艱苦奮斗'
i+=z4.findall(x)#返回['同舟共濟','與時俱進','艱苦奮斗']
i+=z4.findall(x[2:])#返回['舟共濟與','時俱進艱']
i+=z4.findall(x[4:])#返回['共濟與時','俱進艱苦']
i+=z4.findall(x[6:])#返回['濟與時俱','進艱苦奮']
目的是取得所有連續4字中文字元串。
G. 希望介紹個學Python的好網站或者下載資源,或者書本。採納後追加~!謝謝分享
網路雲課堂
http://study.163.com/,裡面有很多不光是python的學習。
比如你找到這個地址中就有python的模塊。
http://study.163.com/find.htm#/find/courselist?ct=31001&ct2=31013
H. 如何用python求出等式裡面的其他的值
python本身不具備這種推導功能, 但Z3可以.
求解器 z3用來解一元一次方程肯定是大材小用了....它可以處理比這復雜得多的情況.
I. 如何使用Z3的Python介面
Z3支持許多平台以及多種語言介面,這里我們簡單介紹其Python介面的使用。
以Mac OS X為例,下載Z3可執行文件後,要設置環境變數PATH和PYTHONPATH:
export PATH=$PATH:<installation path of z3>
export PYTHONPATH=$PYTHONPATH:<installation path of z3>
然後我們編輯一個簡單的例子 stock.py:
#!/usr/bin/env python
from z3 import *
def main (argv):
ds = Real('ds')
fs = Real('fs')
ps = Real('ps')
origin = And ( Not (And (0<=ds, 1<=fs, 1<=ps)),
Implies (And (0<=ds, 0<=fs, 0<=ps), ds<=3),
Implies (And (0<=ds, 0<=fs, 0<=ps, fs<=1), ds+fs<=3),
Implies (And (0<=ds, 0<=ps, 1<=fs, ps<=1), ds+ps<=2))
solver2 = Solver()
solver2.add (origin)
solver2.push()
solver2.add (ds == dv/1000)
solver2.add (fs == fv/1000)
solver2.add (ps == pv/1000)
if solver2.check() == sat:
sat_count2 = sat_count2 + 1
solver2.pop()
從31到33行,聲明3個實數變數,在35行我們定義一個邏輯公式並在47行加入當前環境中,77行調用check()方法並檢查其返回值:sat -- 公式有解;unsat -- 公式無法滿足。注意72,79行的push()和pop()方法是用來暫存和恢復環境。