1、beautifulsoap4 和 scrapy解析和下载网页的代码区别
bs可以离线解释html文件,但是获取html文件是由用户的其他行为的定义的,比如urllib或者request ;
而scrapy是一个完整的获取程序,只需要把网址贴上去,就会自动去爬。 省去很多用户需要关注的细节。
轮子和车子的区别。 前者要依附于一个程序,后者自己就能跑。
beautifulsoap4 的性能比lxml要差
 
2、mongodb非关系型数据库对网页的存储
mongodb安装注意:不用选中compass,这是界面安装,需要下载,很慢
mangodb compass单独下载安装
----------mangodb管理命令----------
net start MongoDB
net stop MongoDB
net restart MongoDB
安装服务
mongod --logpath "F:\mangodbDATA\log\mongodb.log" --logappend --dbpath "F:\mangodbDATA\database" --directoryperdb --install
卸载服务(先要停止服务)
mongod --logpath "F:\mangodbDATA\log\mongodb.log" --logappend --dbpath "F:\mangodbDATA\database" --directoryperdb --remove
重装服务
mongod --logpath "F:\mangodbDATA\log\mongodb.log" --logappend --dbpath "F:\mangodbDATA\database" --directoryperdb --reinstall
 
3、图形界面应用开发pyqt5
 
4、爬虫开发记录
爬纯文本写入TXT,反爬,最多几十章。
直接下载html文件
5秒等待,反爬,单线程下载页面很慢——6分钟60章节
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网页爬虫开发之一的更多相关文章

  1. python网页爬虫开发之三

    1.抓取目录页后用lxml进行页面解析,获取抓取列表 python3.6 urlparse模块变为urllib.parse 2.Python中有一个专门生成各类假数据的库:Faker 3.python ...

  2. python网页爬虫开发之六-Selenium使用

    chromedriver禁用图片,禁用js,切换UA selenium 模拟chrome浏览器,此时就是一个真实的浏览器,一个浏览器该加载的该渲染的它都加载都渲染,所以爬取网页的速度很慢.如果可以不加 ...

  3. python网页爬虫开发之七-多线程爬虫示例01

    from urllib.request import quote import urllib.request from bs4 import BeautifulSoup import re impor ...

  4. python网页爬虫开发之五-反爬

    1.头信息检查是否频繁相同 随机产生一个headers, #user_agent 集合 user_agent_list = [  'Mozilla/5.0 (Windows NT 6.1; WOW64 ...

  5. python网页爬虫开发之四-串行爬虫代码示例

    实现功能:代理.限速.深度.反爬 import re import queue import urllib.parse import urllib.robotparser import time fr ...

  6. Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)

    原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...

  7. 【Python】Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱

    本文转载自:https://www.cnblogs.com/colipso/p/4284510.html 好文 mark http://www.52nlp.cn/python-%E7%BD%91%E9 ...

  8. Python分布式爬虫开发搜索引擎 Scrapy实战视频教程

    点击了解更多Python课程>>> Python分布式爬虫开发搜索引擎 Scrapy实战视频教程 课程目录 |--第01集 教程推介 98.23MB |--第02集 windows下 ...

  9. Python网页爬虫(一)

    很多时候我们想要获得网站的数据,但是网站并没有提供相应的API调用,这时候应该怎么办呢?还有的时候我们需要模拟人的一些行为,例如点击网页上的按钮等,又有什么好的解决方法吗?这些正是python和网页爬 ...

随机推荐

  1. sofa graphql 2 rest api框架

    sofa 是一个出发点不一样的工具,提供了从graphql 2 rest 的处理,一般现有的框架都在 关注的是rest 2 graphql (大部分还是基于swagger.open api 标准进行设 ...

  2. How To Use the AWK language to Manipulate Text in Linux

    https://www.digitalocean.com/community/tutorials/how-to-use-the-awk-language-to-manipulate-text-in-l ...

  3. 03C++语言对C的增强——实用性、变量检测、struct类型、C++中所有变量和函数都必须有类型、bool类型、三目运算符

    1.“实用性”增强 C语言中的变量都必须在作用域开始的位置定义,C++中更强调语言的“实用性”,所有的变量都可以在需要使用时再定义. 2.C++对c语言register的增强 register关键字 ...

  4. unity3d常用组件及分析

  5. 堆的操作(make_heap,push_heap,pop_heap,sort_heap,is_heap)

    堆不是一中sort ranges,堆中的元素不会以递增方式排列,内部以树状形式排列,该结构以每个结点小于等于父节点构成,优先队列就是以堆来实现 make_heap //版本一:用operator &l ...

  6. idea 中maven编译速度过慢的问题的解决

    解决方案一 在创建Maven项目时加上 archetypeCatalog=internal 参数,如下: 解决方案二 在maven的VM Options加上-DarchetypeCatalog=int ...

  7. Qt开发问答

    Qt开发问答 1, Difference between Dialog and widget and QMainWindow http://www.qtcentre.org/threads/3465- ...

  8. sql update操作结果

    Mysql 在MySQL中只有真正对记录进行修改了的情况下,row_count才会去记录影响的行数,否则如果记录存在但是没有实际修改则不会将该次更新记录到row_count中. update操作执行结 ...

  9. Hadoop yarn工作流程详解

    yarn是什么?1.它是一个资源调度及提供作业运行的系统环境平台 资源:cpu.mem等 作业:map task.reduce Task yarn产生背景?它是从hadoop2.x版本才引入1.had ...

  10. Java通过webservice接口获取天气信息

    通过SOAP请求的方式获取天气信息并解析返回的XML文件. 参考: http://www.webxml.com.cn/WebServices/WeatherWS.asmx import java.io ...