详细的讲解我是写在另外一个网址: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的更多相关文章

  1. [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)

    转载自:http://blog.csdn.net/eastmount/article/details/51231852 一. 文章介绍 源码下载地址:http://download.csdn.net/ ...

  2. python 利用selenium爬取百度文库的word文章

    今天学习如何使用selenium库来爬取百度文库里面的收费的word文档 from selenium import webdriver from selenium.webdriver.common.k ...

  3. [Python爬虫] Selenium获取百度百科旅游景点的InfoBox消息盒

    前面我讲述过如何通过BeautifulSoup获取维基百科的消息盒,同样可以通过Spider获取网站内容,最近学习了Selenium+Phantomjs后,准备利用它们获取百度百科的旅游景点消息盒(I ...

  4. Python爬虫(一)爬百度贴吧

    简单的GET请求: # python2 import urllib2 response = urllib2.urlopen('http://www.baidu.com') html = respons ...

  5. python+requests爬取百度文库ppt

    实验网站:https://wenku.baidu.com/view/c7752014f18583d04964594d.html 在下面这种类型文件中的请求头的url打开后会得到一个页面 你会得到如下图 ...

  6. python爬百度文库课件

    库:re;selenium;requests 源码: from selenium import webdriverimport reimport requests def open_img(items ...

  7. Python 爬虫实例(爬百度百科词条)

    爬虫是一个自动提取网页的程序,它为搜索引擎从万维网上下载网页,是搜索引擎的重要组成.爬虫从一个或若干初始网页的URL开始,获得初始网页上的URL,在抓取网页的过程中,不断从当前页面上抽取新的URL放入 ...

  8. Python爬虫(二)爬百度贴吧楼主发言

    爬取电影吧一个帖子里的所有楼主发言: # python2 # -*- coding: utf-8 -*- import urllib2 import string import re class Ba ...

  9. 类似百度文库pdf2swf+flexpaper解决pdf在线阅读的效果

    1:工具准备swftools.exe 下载http://www.swftools.org/download.html 安装至D盘SWFTools提供了一系列将各种文件转成swf的工具:font2swf ...

随机推荐

  1. 学习flask需要用到的包

    Flask 需要下载的包 1.pip install flask 2.pip install flask-script 3.pip install flask-sqlalchemy 4.pip ins ...

  2. STL——string

    C++之string类型详解 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够.字符串长度等等,而且作为一个泛型类出现,他集成的操作函 ...

  3. 小妖精的完美游戏教室——人工智能,A*算法,启发因子篇

    //================================================================//// Copyright (C) 2017 Team Saluk ...

  4. ITextSharp构造PDF文件

    1.1 生成Document Document是我们要生成的PDF文件所有元素的容器,因此要生成一个PDF文档,必须首先定义一个Document对象. Document有三种构造函数:    publ ...

  5. CF D.Mister B and Astronomers

    题意概括好麻烦, 好吧既然是英文题面那放一下题意. 题意:有 n 个观察员,第一个观察员在 0 秒开始观察星空,随后第i 个观察员会在第 i − 1 个观察员之后 ai 秒观察,第一个观察员也会在第 ...

  6. javascript中正则动态替换为对象中的相应数据

    使用正则进行替换以下内容 var str = 'aKey={aValue}&bKey={bValue}' 使用以下对象数据,替换value var obj = { aValue: 1, bVa ...

  7. cordova闪屏插件插件使用:cordova-plugin-splashscreen

    欢迎页本地插件,默认建议包含.启动本地应用时显示指定的图片(启动页) 1. 添加插件:cordova plugin add cordova-plugin-splashscreen 2. 调用方法:

  8. 在linxu机器ansible上运行启动django项目命令

    source py3env/bin/activate  进入虚拟环境 cd /xiangmulujing     进入项目路径 然后就可以执行运行命令了 python manage.py runser ...

  9. servlet_3

    ServletContext 介绍 提供的功能 servlet中获取servletcontext实例 servletcontext接口的方法 package com.fgy; import java. ...

  10. 部署activiti 5.15.1的Activiti Explorer

    1.从官网下载activiti包,将其中的activiti-explorer.war文件拷贝到tomcat的webapps目录下: 2.将mysql驱动包文件mysql-connector-java- ...