濮阳杆衣贸易有限公司

主頁 > 知識庫 > 用python下載百度文庫的代碼

用python下載百度文庫的代碼

熱門標簽:電話機器人電話卡封號怎么辦 開封百應(yīng)電銷機器人聯(lián)系方式 邯鄲外呼調(diào)研線路 北京語音電銷機器人價格 真人語音電銷機器人系統(tǒng) 樂昌電話機器人 武漢呼叫中心外呼系統(tǒng)線路商 浦東上海400開頭的電話申請 買了外呼系統(tǒng)不想用了怎么辦
先去下載一個叫SWFToImage.dll的東西
再建立一個bat文件,并運行:
復(fù)制代碼 代碼如下:

COPY SWFToImage.dll %windir%\system32
regsvr32 %windir%\system32\SWFToImage.dll

復(fù)制代碼 代碼如下:

#用python下載百度文庫的代碼,需要的同志請修改,下面有提示
#http://www.cnblogs.com/dearplain/
#code by plain
import urllib2
import win32com.client
import os
import sys

if __name__=='__main__':
#os.system('');
os.chdir('D:\my project\pywenku')#保存到哪個文件夾
SWFToImage=win32com.client.Dispatch("{479A1AAC-C148-40BB-9868-A9773DA66AF9}");
'''
allfile=os.listdir(".")
findrecord=0
for file in allfile:
if file==".record":
record=open(file,'rw')
findrecord=1
break
if findrecord==0:
record=open('.record','w')
'''
#url="http://wenku.baidu.com/view/8d3ed840be1e650e52ea9938.html?from=recpos=1weight=2lastweight=2count=5"
#url="http://wenku.baidu.com/view/f2fe7a3987c24028915fc37a.html?from=relatedhasrec=1"
#url就是你要下載的文檔的地址
url=sys.argv[1]
if url.find("http://")!=0:
print "error! the url is not correct"
sys.exit()
print "downloading %s"%url
try:
urlReferer=url[url.index('http'):url.index('/v')]
print urlReferer
#urlbody=url[url.index('/v')-1:]
urlnum=url[url.index('ew/')+3:url.index('.htm')]
except ValueError:
print "parse url error"
sys.exit()
#print urlnum
wenku='wenku.baidu.com'
reurl='/play/'
pagefrom='?pn='
downnum='rn='
#try to get title and make dir
req=urllib2.Request(url)
res=urllib2.urlopen(req)
data=res.read()
try:
sfrom=data.index('title>')+len('title>')
#print sfrom
sbefore=sfrom+data[sfrom:].index('/title>')
#print sbefore
title=data[sfrom:sbefore]
title=title[:title.rindex('_')]
print 'downloading '+title
except ValueError:
print "get title error"
sys.exit()
allfile=os.listdir(".")
if (title in allfile)==False:
os.mkdir(title)
os.chdir('./'+title)
#get the first swf
req=urllib2.Request('http://wenku.baidu.com'+reurl+urlnum+pagefrom+'1'+downnum+'1')
req.add_header("Referer", urlReferer )
res=urllib2.urlopen(req)
data=res.read()
res.close()
head=data[0:45]
pagenum=0
sfrom=head.index('\":\"')+len('\":\"')
sbefore=sfrom+head[sfrom:].index('\"')
pagenum=int(head[sfrom:sbefore])
print 'pagenum:'+str(pagenum)
if pagenum=0 or pagenum>2000:
print "error!!!pagenum0 or pagenum>2000"
sys.exit()
data=data[106:]

swf=open("1.pywenku",'wb')
swf.write(data)
swf.close()
i=1
SWFToImage.InputSWFFileName="%d.pywenku"%i
SWFToImage.ImageOutputType = 1
SWFToImage.ImageWidth=1048
SWFToImage.ImageHeight=1478
SWFToImage.Execute_Begin()
SWFToImage.FrameIndex = 1
SWFToImage.Execute_GetImage()
SWFToImage.SaveToFile("%d.jpg"%i)
SWFToImage.Execute_End()
os.rename("%d.pywenku"%i,"%d.swf"%i)
allfile=os.listdir(".")
#從第二頁下到最后一頁
for i in range(2,pagenum+1):

if '%d.swf'%i in allfile:
continue
#not find in the dir mean
req=urllib2.Request('http://wenku.baidu.com'+reurl+urlnum+pagefrom+str(i)+downnum+'1')
res=urllib2.urlopen(req)
data=res.read()
data=data[106:]
swf=open("%d.pywenku"%i,'wb')
swf.write(data)
swf.close()
SWFToImage.InputSWFFileName="%d.pywenku"%i
SWFToImage.ImageOutputType = 1
SWFToImage.Execute_Begin()
SWFToImage.FrameIndex = 1
SWFToImage.Execute_GetImage()
SWFToImage.SaveToFile("%d.jpg"%i)
SWFToImage.Execute_End()
os.rename("%d.pywenku"%i,"%d.swf"%i)
res.close()
print 'task complete'
您可能感興趣的文章:
  • python 爬取百度文庫并下載(免費文章限定)
  • Python實現(xiàn)的爬取百度文庫功能示例
  • python 爬蟲如何實現(xiàn)百度翻譯
  • 詳解用Python爬蟲獲取百度企業(yè)信用中企業(yè)基本信息
  • Python爬蟲爬取百度搜索內(nèi)容代碼實例
  • Python爬蟲實現(xiàn)百度翻譯功能過程詳解
  • python 爬蟲百度地圖的信息界面的實現(xiàn)方法
  • python爬蟲之爬取百度音樂的實現(xiàn)方法
  • Python爬蟲實現(xiàn)爬取百度百科詞條功能實例
  • python爬蟲獲取百度首頁內(nèi)容教學(xué)
  • Python爬蟲實現(xiàn)百度圖片自動下載
  • Python爬蟲實例_利用百度地圖API批量獲取城市所有的POI點
  • python實現(xiàn)百度文庫自動化爬取

標簽:宜春 松原 六安 河北 鄂州 淄博 自貢 石嘴山

巨人網(wǎng)絡(luò)通訊聲明:本文標題《用python下載百度文庫的代碼》,本文關(guān)鍵詞  用,python,下載,百度,文庫,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《用python下載百度文庫的代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于用python下載百度文庫的代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    玉田县| 方山县| 峨眉山市| 石景山区| 涪陵区| 平凉市| 葵青区| 玉门市| 永仁县| 自治县| 建昌县| 宝清县| 平乐县| 新乡市| 雷波县| 利川市| 亚东县| 九台市| 抚州市| 大理市| 岐山县| 东乡县| 海城市| 邵武市| 建宁县| 修武县| 米易县| 马公市| 瓮安县| 桐梓县| 文成县| 尉氏县| 盐池县| 台南市| 桐乡市| 临猗县| 贺州市| 屏南县| 仁布县| 额尔古纳市| 临城县|