python使用selenium爬百度文库ppt并生成pdf
详细的讲解我是写在另外一个网址:https://www.yuque.com/docs/share/aacfa45c-22c5-4ef6-be97-cd6849002274
有点尬尴,所以就.....
在这里直接放下另外一个例子(《数学模型答案》)的代码
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
import time
import re
import requests class downloader:
def __init__(self):
self.browser =webdriver.Chrome()
self.wait =wait = WebDriverWait(self.browser,3)
self.i=0
self.pattern =re.compile('.*?url\("(.*?)"\)',re.S) def __call__(self,url):
self.download(url)
while True:
for i in self.parse_link():
self.save(i) sub =self.browser.find_element_by_id('next-pageList-1')
self.browser.execute_script("arguments[0].scrollIntoViewIfNeeded(true);",sub)
sub.click() self.browser.quit() def download(self,url):
self.browser.get(url)
submit =self.wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="html-reader-go-more"]/div[2]/div[1]/span/span[1]')))
self.browser.execute_script("arguments[0].scrollIntoViewIfNeeded(true);",submit)
submit.click() def parse_link(self):
self.elem=self.wait.until(EC.presence_of_element_located((By.ID,'reader-container-inner-1')))
for i in self.elem.find_elements_by_class_name('bd'):
try:
self.browser.execute_script("arguments[0].scrollIntoViewIfNeeded(true);",i)
time.sleep(0.6)
i =i.find_element_by_class_name('reader-pic-item') js=i.get_attribute('style') href =self.pattern.findall(js)
yield href[0]
except NoSuchElementException:
continue def save(self,link):
html =requests.get(link).content
with open('{}.png'.format(self.i),'wb') as f:
f.write(html)
self.i +=1 D =downloader()
D('https://wenku.baidu.com/view/d86fe3436c175f0e7dd13731')
python使用selenium爬百度文库ppt并生成pdf的更多相关文章
- [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)
转载自:http://blog.csdn.net/eastmount/article/details/51231852 一. 文章介绍 源码下载地址:http://download.csdn.net/ ...
- python 利用selenium爬取百度文库的word文章
今天学习如何使用selenium库来爬取百度文库里面的收费的word文档 from selenium import webdriver from selenium.webdriver.common.k ...
- [Python爬虫] Selenium获取百度百科旅游景点的InfoBox消息盒
前面我讲述过如何通过BeautifulSoup获取维基百科的消息盒,同样可以通过Spider获取网站内容,最近学习了Selenium+Phantomjs后,准备利用它们获取百度百科的旅游景点消息盒(I ...
- Python爬虫(一)爬百度贴吧
简单的GET请求: # python2 import urllib2 response = urllib2.urlopen('http://www.baidu.com') html = respons ...
- python+requests爬取百度文库ppt
实验网站:https://wenku.baidu.com/view/c7752014f18583d04964594d.html 在下面这种类型文件中的请求头的url打开后会得到一个页面 你会得到如下图 ...
- python爬百度文库课件
库:re;selenium;requests 源码: from selenium import webdriverimport reimport requests def open_img(items ...
- Python 爬虫实例(爬百度百科词条)
爬虫是一个自动提取网页的程序,它为搜索引擎从万维网上下载网页,是搜索引擎的重要组成.爬虫从一个或若干初始网页的URL开始,获得初始网页上的URL,在抓取网页的过程中,不断从当前页面上抽取新的URL放入 ...
- Python爬虫(二)爬百度贴吧楼主发言
爬取电影吧一个帖子里的所有楼主发言: # python2 # -*- coding: utf-8 -*- import urllib2 import string import re class Ba ...
- 类似百度文库pdf2swf+flexpaper解决pdf在线阅读的效果
1:工具准备swftools.exe 下载http://www.swftools.org/download.html 安装至D盘SWFTools提供了一系列将各种文件转成swf的工具:font2swf ...
随机推荐
- 12集合(2)-----Set
一.总体分类 Collection(包括方法add,remove,contains,clear,size) List(接口) LinkedList ArrayList Vector---Stack 2 ...
- 使用[].forEach.call()方法的写拖拽排序。
---恢复内容开始--- }); });}要引用两个插件: <script src="./jquery.1.12.4.min.js"></script> & ...
- tornado上帝视角第一次建立WEB服务器
import tornado.ioloop import tornado.web 该视角建立在SOCKET服务端和客户端的基础上. class MainHandler(tornado.web.Requ ...
- unity 常用插件 3
一. 遮罩插件 Alpha Mask UI Sprites Quads 1.51 介绍:功能感觉很强大的一个遮罩插件,能实现LOGO高光闪动动画,圆形遮罩,透明通道图片遮罩,还真是项目必备. ...
- mac下 部分服务启动,结束, 查看状态的命令
以sshd服务为例 启动sshd服务:sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist 停止sshd服务:sudo laun ...
- 巴黎游戏周: PS4独占游戏《重力少女2》
http://blog.us.playstation.com/2015/10/27/gravity-rush-2-coming-to-north-america-on-ps4/
- js数据三大储存格式
一.String格式 做为一个前端者 你第一手得到的数据都是字符串 二.数组格式 1.定义 var arr=[“张三”,”李四”,”王五”]; 数据通过索引去查找对应的元素 arr[3] 2. ...
- R实用小技巧
输出重定向 # 文本重定向 # cat cat("hello",file="D:/test.txt", append=T) # sink("filen ...
- 结合数据结构来看看Java的String类
数据结构中定义字符串是由零个或多个字符组成的有限序列,有限,指出字符串的长度是一个有限的数值:所谓的序列,说明串的相邻字符之间具有前驱和后继的关系.字符串一般记为s="a1a2...an&q ...
- angular2的ElementRef在组件中获取不到
angular2的ElementRef在组件中获取不到 angular2不推荐操作dom,但是实际应用中不可避免的需要使用到dom操作,怎么操作,官方文档提供了一系列api(ElementRef,Vi ...