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和网页爬 ...
随机推荐
- nodejs-hook 开发
nodejs require hook 功能很强大,我们可以用来将不支持的数据文件,直接使用require 进行加载,同时 我们可以方便的进行代码的预编译(比如babel 的组件) 为了方便使用npm ...
- Bow & Arrow 学习
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; ...
- DevExpress 控件使用菜单栏之BarManager
DevExpress 开发的控件有很强的实力,不仅功能丰富,应用简便,而且界面华丽,更可方便定制.对于编程人员来说是个不错的选择.它的菜单栏控件更具代表,完全可以替代开发环境提供的基本控件,而让您编写 ...
- Laya学习
IDE安装 https://www.jianshu.com/p/88fa76a5becc npm uninstall -g typescript npm install -g typescript@2 ...
- Linux服务器定位CPU高占用率代码位置经历
http://blog.csdn.net/zhu19774279/article/details/51303000
- laravel ORM 模型关联 with () 用法
关联时想对关联表数据筛选时:MySQL查询: SELECT * FROM A LEFT JOIN B ON A.B_id = B.id AND B.condition = $condition ORM ...
- 3、Sql-Ora-01033:oracle initialization or shutdown in progress
- golang channel几点总结
golang提倡使用通讯来共享数据,而不是通过共享数据来通讯.channel就是golang这种方式的体现. Channel 在golang中有两种channel:带缓存的和不带缓存. 带缓存的cha ...
- Hanlp在ubuntu中的使用方法介绍
HanLP的一个很大的好处是离线开源工具包,换而言之,它不仅提供免费的代码免费下载,而且将辛苦收集的词典也对外公开啦,此诚乃一大无私之举.我在安装的时候,主要参照这份博客: blog.csdn.net ...
- Linux rcp命令详解
Linux rcp命令 Linux rcp命令用于复制远程文件或目录. rcp指令用在远端复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件 ...