python网页爬虫开发之一
req = request.Request(url, headers=headers)
resp = request.urlopen(req)
strhtml = resp.read().decode('gbk', 'ignore')
html_soup = BeautifulSoup(strhtml, 'lxml')
# index = BeautifulSoup(str(html_soup.find_all('div', class_='dir')), 'lxml')
# print(html_soup.find_all(['td', ['span']]))
body_flag = 0
spanId = '' for element in html_soup.find_all(['td', ['span']]):
if element.has_attr('id'):
signId = element['id']
if signId == 'jianjie': body_flag = 1
if signId == 'xs555' or signId == 'd999': body_flag = 0
# else:body_flag = 0 if body_flag == 1 and element.name == 'td':
if not element.a is None:
chapter_name = element.string
chapter_url = "https://www.555zw.com/book/40/40943/" + element.a.get('href')
data = {
'chapter_name': chapter_name,
'chapter_url': chapter_url
}
chapters.insert_one(data)
with open(filename, "a") as f:
responses = request.urlopen(item["chapter_url"])
time.sleep(5)
contents = responses.read().decode('gbk', 'ignore').encode('utf8')
f.write(contents)
#origin_soup = BeautifulSoup(contents, 'lxml')
#content = origin_soup.find(id='content')
#move = dict.fromkeys((ord(c) for c in u"\xa0\r\t"))
#txt = content.text.translate(move)
#txt = content.text
python网页爬虫开发之一的更多相关文章
- python网页爬虫开发之三
1.抓取目录页后用lxml进行页面解析,获取抓取列表 python3.6 urlparse模块变为urllib.parse 2.Python中有一个专门生成各类假数据的库:Faker 3.python ...
- python网页爬虫开发之六-Selenium使用
chromedriver禁用图片,禁用js,切换UA selenium 模拟chrome浏览器,此时就是一个真实的浏览器,一个浏览器该加载的该渲染的它都加载都渲染,所以爬取网页的速度很慢.如果可以不加 ...
- python网页爬虫开发之七-多线程爬虫示例01
from urllib.request import quote import urllib.request from bs4 import BeautifulSoup import re impor ...
- python网页爬虫开发之五-反爬
1.头信息检查是否频繁相同 随机产生一个headers, #user_agent 集合 user_agent_list = [ 'Mozilla/5.0 (Windows NT 6.1; WOW64 ...
- python网页爬虫开发之四-串行爬虫代码示例
实现功能:代理.限速.深度.反爬 import re import queue import urllib.parse import urllib.robotparser import time fr ...
- Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)
原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...
- 【Python】Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
本文转载自:https://www.cnblogs.com/colipso/p/4284510.html 好文 mark http://www.52nlp.cn/python-%E7%BD%91%E9 ...
- Python分布式爬虫开发搜索引擎 Scrapy实战视频教程
点击了解更多Python课程>>> Python分布式爬虫开发搜索引擎 Scrapy实战视频教程 课程目录 |--第01集 教程推介 98.23MB |--第02集 windows下 ...
- Python网页爬虫(一)
很多时候我们想要获得网站的数据,但是网站并没有提供相应的API调用,这时候应该怎么办呢?还有的时候我们需要模拟人的一些行为,例如点击网页上的按钮等,又有什么好的解决方法吗?这些正是python和网页爬 ...
随机推荐
- Redis Cluster 4.0高可用集群安装、在线迁移操作记录
之前介绍了redis cluster的结构及高可用集群部署过程,今天这里简单说下redis集群的迁移.由于之前的redis cluster集群环境部署的服务器性能有限,需要迁移到高配置的服务器上.考虑 ...
- taro 最佳实践
对 JSX 支持程度补充说明: 不能在包含 JSX 元素的 map 循环中使用 if 表达式 不能使用 Array#map 之外的方法操作 JSX 数组 不能在 JSX 参数中使用匿名函数 暂不支持在 ...
- BeanShell用法(摘抄至网络)
说明:本文部分资料摘抄至 来源: http://www.cnblogs.com/puresoul/p/4915350.html 来源: http://www.cnblogs.com/puresoul/ ...
- vs2013 使用vs2017的localdb
应用vs203进行MVC开发时,进行数据库初始化的时候,默认使用电脑中高版本的localdb(v12),在修改web.config中的链接串时报错,也无法使能数据库迁移, 解决方法:在数据库初始化之前 ...
- DevExpress GridView 那些事儿
1:去除 GridView 头上的 "Drag a column header here to group by that column" --> 点击 Run Desig ...
- JS 判断IE(转)
一.: 之前,js判断的方式都是利用浏览器的useragent字段.通过判断useragent字段里面是否包含有MSIE字段来判断是否是IE系列浏览器,屡试不爽. 但是在IE11之后,微软把自家的IE ...
- 利用JavaFx开发RIA桌面应用-事件监听
1 事件监听 最近利用javaFX开发桌面客户端,碰到需要给各种UI控件添加事件监听,在这里做一个简单的小结,供日后参考. 2 分类处理 在JavaGUI 和Android中,事件通常通过实现list ...
- Avalon总线学习 ---Avalon Interface Specifications
Avalon总线学习 ---Avalon Interface Specifications 1.Avalon Interfaces in a System and Nios II Processor ...
- Java事件监听器的四种实现方式
自身类作为事件监听器 外部类作为事件监听器 匿名内部类作为事件监听器 内部类作为事件监听器 自身类作为事件监听器: import javax.swing.*; import java.awt.*; i ...
- git log乱码显示
1.Linux下UTF8编码 [xusi@pre-srv24 crm2]$ localeLANG=en_US.UTF-8 设置如下: git config --global i18n.commiten ...