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 ...
随机推荐
- s21day19 python笔记
s21day19 python笔记 一.面向对象的基本知识 1.1 基本格式 # 定义类 class 类名: def 方法名(self,name): print(name) return 123 de ...
- MySQL 8.0.13 下载安装教程
MySQL是使用最多的数据库,自己电脑上肯定要装一个来多加学习,自己搞不懂的一些东西要多写一些 sql 语句练习. 首先去 mysql 官网下载,地址:https://dev.mysql.com/do ...
- SQL SEVER 时间格式转换
常用:时分秒(HH:mm:ss):Select CONVERT(varchar(100), GETDATE(), 8) : 10:57:46年月日 (yyyyMMdd):Select CONVERT( ...
- hql和sql的一些区别
日期格式化查询的区别: selectSql.append(" AND DATE_FORMAT(o.createDate,\'%Y-%m-%d\') = :createDate"); ...
- Spring Boot + JPA 因为 javassist 包出现 NullPointerException 问题的解决
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.ent ...
- Linux 的基本命令
Linux 的基本命令 1. 文件操作 a) Windows 是多根的文件系统,物理上是 1 到多块硬盘,逻辑上分为 C.D.E……盘, 每个盘都是一棵树.Linux 是单根的文件系统,不分 CDE ...
- html2canvas将页面内容生成图片
html2canvas官网链接地址:https://html2canvas.hertzen.com/ <!doctype html> <html lang="en" ...
- impdp如何杀掉job
今天刚执行一个impdp操作发现,硬盘空间可能不够了,赶紧按了Ctrl+C,结果发现磁盘空间仍然在减少.问了一下部门oracle专家,Ctrl+C是无法停止impdp的job的.需要将job进行att ...
- mac电脑上如何启动mysql
export PATH=$PATH:/usr/local/mysql/bin/ mysql -uroot -p
- 左耳听风-ARTS-第2周(2019/3/31-2019/4/6)
Algorithm 验证括号题(https://leetcode.com/problems/valid-parentheses/).这道题在极客时间上覃超的<算法面试通关40讲>(http ...