获取特定html源码 富文本编辑器 爬虫生成 dom
python beautifulsoup获取特定html源码 - 吴悟无 - 博客园 https://www.cnblogs.com/vickey-wu/p/6843411.html
PyQuery库的使用 - CSDN博客 https://blog.csdn.net/qw_xingzhe/article/details/75175256
Python爬虫:PyQuery库的介绍与使用 - 简书 https://www.jianshu.com/p/c07f7cd1b548
pyquery相当于jQuery的python实现,可以用于解析HTML网页等。它的语法与jQuery几乎完全相同,对于使用过jQuery的人来说很熟悉,也很好上手。
引用作者的原话就是:
“The API is as much as possible the similar to jquery.” 。
from selenium import webdriver
import time
import random
from bs4 import *
from pyquery import PyQuery as pq browser = webdriver.Chrome()
url = 'https://so.gushiwen.org/shiwenv_ee16df5673bc.aspx'
browser.get(url) js = "a_=document.getElementsByTagName('a');le=a_.length;for(i=0;i<le;i++){if(a_[i].text=='展开阅读全文 ∨'){try{a_[i].click()}catch(err){console.log(err)}}}"
try:
browser.execute_script(js)
except Exception as e:
print(e)
ck_l_ori_len = len(browser.find_elements_by_link_text('展开阅读全文 ∨'))
ck_l_ori_ok = 0
try:
for isc in range(100):
if ck_l_ori_ok == ck_l_ori_len:
break
time.sleep(1)
js = 'window.scrollTo(0,document.body.scrollHeight)'
js = 'window.scrollTo(0,100*{})'.format(isc)
browser.execute_script(js)
ck_l = browser.find_elements_by_link_text('展开阅读全文 ∨')
for i in ck_l:
try:
i.click()
ck_l_ori_ok += 1
except Exception as e:
print(e)
except Exception as e:
print('window.scrollTo-->', e) doc = pq(browser.page_source)
pq_r_d = {'xmlns="http://www.w3.org/1999/xhtml"': ''}
r_k, r_v = 'xmlns="http://www.w3.org/1999/xhtml"', ''
article_ = doc('.left>:nth-child(2).sons>.cont>.contson').html().replace(r_k, r_v)
title_d = {'h1': doc('.left>:nth-child(2).sons>.cont>:nth-child(2)').html().replace(r_k, r_v)}
author_d = {'h3': doc('.left>:nth-child(2).sons>.cont>:nth-child(3)').text()}
translation_ = doc('.left>:nth-child(4)>.contyishang>:nth-child(2)').html().replace(r_k, r_v)
explanation_ = doc('.left>:nth-child(4)>.contyishang>:nth-child(3)').html().replace(r_k, r_v)
refer_ = doc('.left>:nth-child(4)>.cankao').html().replace(r_k, r_v) author_img_url = doc('.left>.sonspic>.cont>.divimg>:nth-child(1)').html().split('src="')[-1].split('"')[0] k = 'h1'
v = title_d[k]
db_html = '<{}>{}</{}>'.format(k, v, k)
k = 'h3'
v = author_d[k]
db_html = '{}<{}>{}</{}>'.format(db_html, k, v, k)
db_html = '{}{}'.format(db_html, '<br><img src="{}" ><br>'.format(author_img_url))
l = [db_html, article_, explanation_, translation_, refer_]
db_html = '<br><br>'.join(l) rp_s_l = ['<a href=', '<a href=', '<a title=', '<a title=']
for rp_s in rp_s_l:
img_n = db_html.count(rp_s)
for i in range(img_n):
p1 = db_html.index(rp_s, 0)
tmp = '{}{}'.format(db_html[0:p1].replace('>', 'X'), db_html[p1 + 1:])
p2 = tmp.index('>')
db_html = '{}{}{}'.format(db_html[0:p1], '', db_html[p2 + 1:])
获取特定html源码 富文本编辑器 爬虫生成 dom的更多相关文章
- python beautifulsoup获取特定html源码
beautifulsoup 获取特定html源码(无需登录页面) import refrom bs4 import BeautifulSoupimport urllib2 url = 'http:// ...
- 富文本编辑器Quill(一)简单介绍
Quill是一个很流行的富文本编辑器,github上star大约21k: github:https://github.com/quilljs/quill/ 官网: https://quilljs.co ...
- 轻量级富文本编辑器wangEditor源码结构介绍
1. 引言 wangEditor——一款轻量级html富文本编辑器(开源软件) 网站:http://www.wangeditor.com/ demo演示:http://www.wangeditor.c ...
- 简易富文本编辑器bootstrap-wysiwyg源码注释
好久没写随笔了,因为最近比较忙,小公司基本都是一个前端干所有属于和部分不属于前端的事情,所以就没空弄了,即使想分享,也因为没有时间和精力就搁置了. 这周周六日休息,正好时间比较充裕(ps:目前处在单休 ...
- quillJS 富文本编辑器源码分析系列1
quillJS 富文本编辑器目前是一款很火富文本编辑器,使用广泛,github 上面的 star 有 22,492,虽然说不以 star 论英雄,不过这可以说明它还是比较受欢迎的: 它的特点是:轻量, ...
- 使用百度UMeditor富文本编辑器,修改自定义图片上传,修改源码
富文本编辑器,不多说了,这个大家应该都用到过,至于用到的什么版本,那就分很多种 CKEditor:很早以前叫FCK,那个时候也用过,现在改名了,比较流行的一个插件,国外很多公司在用 UEDITOR:百 ...
- easyUI整合富文本编辑器KindEditor详细教程(附源码)
原因 在今年4月份的时候写过一篇关于easyui整合UEditor的文章Spring+SpringMVC+MyBatis+easyUI整合优化篇(六)easyUI与富文本编辑器UEditor整合,从那 ...
- 富文本编辑器--获取JSON
获取 JSON 格式的内容 可以通过editor.txt.getJSON获取 JSON 格式的编辑器的内容,v3.0.14开始支持,示例如下 <div id="div1"&g ...
- 【React】富文本编辑器 清空文本内容 获取HTML
富文本编辑器 React 传入 import React,{Component } from 'react'; import { Card, Button, Table, Form, Select ...
随机推荐
- http和socket
大多数情况下都是使用Http协议做网络通信的,少数情况下,如扣扣之类的即时通讯,就是用Socket建立长链接 Http一般都是短连接的,即客户端和服务端通讯一次后,服务端就关闭连接 Socket是长连 ...
- (C/C++学习)17.bitset(位操作)
说明:bitset 就像 vector 一样,是 C++ 的一个类模板库,用来对一个数的二进制位进行管理.判断等操作,使用时需要包含头文件 #include<bitset>. 1.声明及定 ...
- 在git提交时忽略已提交过或从线上拉取下来但本地已修改的文件
一.忽略: git update-index --assume-unchanged [file-path] 命令中的file-path 就是需要忽略提价的文件的路径 例子: git update-in ...
- tomcat:页面跳转
vim index.html <script language="javascript"type="text/javascript"> window ...
- Python:os模块 time模块
1.os os.popen('cmd').read() 执行某个系统命令,:输出命令结果 os.getcwd() 获取当前操作目录 os.makedirs(r"C:\a\b\c" ...
- Jmeter关联,正则表达式提取器使用2
正则表达式的用处很多,最基础的用法 1,断言 2,传参(关联) 例子 1.http请求 2正则表达式提取,想要提取列表列中id,一遍打开列表页 如果是1,每次就会取相同的值!匹配数字的权限高于模板$0 ...
- 有三个数a,b,c要求按大小顺序将其输出<if,else语句的学习>
#include <stdio.h> /* 有三个数a,b,c要求按大小顺序将其输出 ----------soulsjie 20170525------ */ void main(){ i ...
- HDU——1285 确定比赛名次
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 洛谷 P4470 [BJWC2018]售票
P4470 [BJWC2018]售票 C 市火车站最近出现了一种新式自动售票机.买票时,乘客要先在售票机上输入终点名称.一共有N 处:目的地,随着乘客按顺序输入终点名称的每个字母,候选终点站数目会逐渐 ...
- Ubuntu 16.04无损分区大小调整工具Gparted
安装: sudo apt-get install gparted 使用: 注意: 这款软件可以调整分区大小,且支持无损,但是对于/根目录的分区无法调整,但是它提供ISO工具,可以启动后进行调整. 下载 ...