详细的讲解我是写在另外一个网址: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. scroll-view

    scroll-view 中分别有上下竖向滑动和左右横向滑动之分,在这次项目中刚好需要用到横向滑动,但在测试过程中发现横向滑动没有了效果(静止在那里没移动过),经调试发现: 1.scroll-view ...

  2. 不同系统、不同存储格式(textfile, parquet)数据的传递

    描述: 本地测试环境hive中有数据,存储格式为textfile,现在要上传到公司开发环境,存储格式为parquet, 如何实现??? tb_textfile表---> local file - ...

  3. myEclipse出现cannot paste the clipboard contents into the selected elements报错

    导入jar包报错,cannot paste the clipboard contents into the selected elements,查阅资料让重新打开工程,但依然报错. 最后在本地路径复制 ...

  4. redis配置文件说明

    redis.conf 配置项说明如下: Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 当Redis以守护进程方式运行时,Redis默认 ...

  5. Educational Codeforces Round 54 (Rated for Div. 2) D:Edge Deletion

    题目链接:http://codeforces.com/contest/1076/problem/D 题意:给一个n个点,m条边的无向图.要求保留最多k条边,使得其他点到1点的最短路剩余最多. 思路:当 ...

  6. SQL server 多个字段设为主键

    create table teacher_course( ton char(8) not null, classno char(8) not null, con char(4) not null pr ...

  7. Visual Studio 2017 Android 调试无法连接到虚拟机

    输出窗口输出如下: 1>Starting deploy 4.5" KitKat (4.4) HDPI Phone ... 1>Starting emulator 4.5" ...

  8. docker下搭建fastfds

    https://blog.csdn.net/weixin_40247263/article/details/81087726 搭建过程参考 作者 https://me.csdn.net/feng_qi ...

  9. PythonStudy——PyCharm使用技巧 Column Selection Mode(列选择模式)

    PyCharm的Column Selection Mode提供了列选择功能. 使用: 在当前文件右键->Column Selection Mode->用鼠标垂直选择文本 快捷键:Alt + ...

  10. 2018-2019-2 20175202实验二《Java面向对象程序设计》实验报告

    2018-2019-2 20175202实验二<Java面向对象程序设计>实验报告 一.实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初 ...