[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 ivor 于 2017-11-24 21:40 编辑

回复 1# wzf1024


Python3.5
下载地址保存为list.txt,复制到迅雷批量下载
  1. # coding:utf-8
  2. import bs4
  3. import urllib.request as url
  4. web_site = 'http://pmmp.cnki.net/OperatingDiscipline/Details.aspx?id=%s'
  5. with open('list.txt','w') as wfile:
  6.     for num in range(10001,16715):
  7.         try:
  8.             req = url.urlopen(web_site % str(num)[1:])
  9.             soup = bs4.BeautifulSoup(req,'html.parser')
  10.             for i in soup.find_all('a'):
  11.                 if i.string == '全文下载':
  12.                     downloadUrl = url.unquote(i.get('href'))
  13.                     print(downloadUrl, file=wfile, flush=True)
  14.                     print(downloadUrl)
  15.                     break      
  16.         except:
  17.             print("服务器错误!请检查网址连接    当前id=%s" % str(num)[1:])
  18.             pass
  19. input("回车结束")
复制代码
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

回复 6# codegay


    好
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

本帖最后由 ivor 于 2017-11-24 21:34 编辑

回复 1# wzf1024


   
我爬下来的pdf链接
2

评分人数

#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

回复 12# 775405984


    下载链接更新了,建议你学学Python。
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

回复 17# 775405984


    https://pan.baidu.com/s/1dGQORIh
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

本帖最后由 ivor 于 2018-2-20 10:19 编辑

换了个思路,采用list弹出元素的方式,发现还是很方便的哈,效率主要还是看服务器处理的速度。
10个线程够这下速度够快了吧。。。
  1. # coding:utf-8
  2. # 10线程
  3. #
  4. import bs4
  5. import urllib.request as url
  6. import threading
  7. import time
  8. s = time.time()
  9. pdfUrl = []
  10. numList = ['{:0>4}'.format(i) for i in range(1, 2150)]
  11. def getPdfUrl(threadKey = 'default'):
  12.     web_site = r'http://pmmp.cnki.net/OperatingDiscipline/Details.aspx?id=%s'
  13.     while len(numList):
  14.         num = numList.pop()
  15.         try:
  16.             req = url.urlopen(web_site % num)
  17.             soup = bs4.BeautifulSoup(req,'html.parser')
  18.             for i in soup.find_all('a'):
  19.                 if i.string == '全文下载':
  20.                     pdf = url.unquote(i.get('href'))
  21.                     pdfUrl.append(pdf + '\n')
  22.                     print("Thread[%s]: %s" % (threadKey,pdf))
  23.                     break
  24.             
  25.         except:
  26.             print("服务器错误!   当前id=%s" % num)
  27.             
  28.     print("Thread[%s]: End!!" % threadKey)
  29.     return
  30. def writeList(pdfLink):
  31.     with open("list.txt", "w") as file:
  32.         file.writelines(pdfLink)
  33. #线程实体list
  34. t = ['t1','t2','t3','t4','t5','t6','t7','t8','t9','t10']
  35. for i in t:
  36.     i = threading.Thread(target=getPdfUrl,args=(i,))
  37.     i.start()
  38. while True:
  39.     time.sleep(1)
  40.     if threading.active_count() == 1:
  41.         writeList(pdfUrl)
  42.         print("\n\n耗时: %f 秒" % (time.time() - s))
  43.         break
复制代码
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

返回列表