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 ...
随机推荐
- CSS背景样式和列表样式
background-color 设置元素的背景颜色 background-image 把图像设置为背景 background-position 设置背景图像的起始位置 background-atta ...
- s21day17 python笔记
s21day17 python笔记 一.内容回顾及补充 回顾 补充 第三方模块补充 需要下载安装后才能导入使用 安装方式: pip包管理工具 # 把pip.exe 所在的目录添加到环境变量中. pip ...
- systemd的新特性及unit常见类型分析与awk用法示列
简述systemd的新特性及unit常见类型分析,能够实现编译安装的如nginx\apache实现通过systemd来管理 系统引导的新特性 系统引导时实现服务启动: 按需激活进程: 系统状态快照: ...
- PIL库的总结及运用
PIL库的总结:(以代码形式) #date: 2018/11/15 from PIL import Image,ImageFilter,ImageDraw,ImageFont #####除了缩略图的方 ...
- 在树莓派2或3的kali上 RCA(a/v connector)接口的正确使用方法(多图)(原创)
AV接口又称(RCA),AV接口算是出现比较早的一种接口,它由黄.白.红三种颜色的线组成,其中黄线为视频,红色为左声道,白色为右声道. ...
- jquery 蔚蓝网
$(document).ready(function(){ //提交表单 $("#registerBtn").click(function(){ var email=documen ...
- jquery案例
调用js成员 <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>& ...
- 虚拟机安装精简版centos7过程
虚拟机配置工作如下所示 1.创建虚拟机 使用键盘组合键CTRL+N2.选择自定义(高级) 如图所示: 3.默认如何所示: 4.选择 稍后安装操作系统 如图所示: 5.选择对应的操作系统 如何所示 6 ...
- 【转载】【原创】华硕F8TR笔记本更换主板及喇叭教程
转载地址:http://blog.sina.com.cn/s/blog_6241aaed0102w4e6.html [原创]华硕F8TR笔记本更换主板及喇叭教程 华硕AUSU F8TR笔记本 ...
- 前端基础:web语义化
web语义化 一.什么是web语义化? web语义化包含两方面,一是html标签语义化,简单来说就是要用合适的标签来表述适当的内容,标题用<h1>~~<h6>标签,段落用< ...