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和网页爬 ...
随机推荐
- pycharm 的操作1
- python 基础的用法新发现
引用的发现: # 引用的处理 因为变量指的是某一内存地址 引用变量实际是引用一个固定的内存地址,# 当这个变量中的内容变了之后,他的内存地址不变, 所以引用者也动态的得到了变化的变量l1=[1,2,3 ...
- 续drone 1.0 新界面调整
接以前的内容,drone 最新发布的版本又有界面信息的调整了,更方便了. 环境准备 docker-compose 文件 version: '3' services: drone-server: ima ...
- CDH5上安装Hive,HBase,Impala,Spark等服务
Apache Hadoop的服务的部署比較繁琐.须要手工编辑配置文件.下载依赖包等.Cloudera Manager以GUI的方式的管理CDH集群,提供向导式的安装步骤.因为须要对Hive,HBase ...
- script标签的同步和异步
1).把<script>标签放在<head>中意味着必须等到全部的js代码都下载解析和执行完成以后,才开始展现页面内容,为避免这个问题一般把js代码全部放在<body&g ...
- 十一、springboot(六)整合Thymeleaf
1.添加jar包依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId ...
- windows下安装python-Levenshtein
安装python-Levenshtein 报错 error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Vi ...
- C166-变量和函数指定物理地址一
1.函数指定地址 按照http://www.keil.com/support/docs/2215.htm C166: LOCATING PROGRAM SECTIONS TO SPECIAL MEMO ...
- Typescript学习总结之类
1. 类的定义和使用 class Student { name; say() { console.log(this.name + " saying"); } } var s1 = ...
- java jvm设置http代理参数
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1080