python输出古诗词_python爬虫——爬取古诗名句
一. 概要
1.通过python爬虫循环爬取古诗词网站古诗名句
2.落地到本地数据库
二. 页面分析
首先通过firedebug进行页面定位:
其次源码定位:
最终生成lxml etree定位div标签源码:
response = etree.HTML(data)
for row in response.xpath('//div[@class="left"]/div[@class="sons"]/div[@class="cont"]'):
content = row.xpath('a/text()')[0]
origin = row.xpath('a/text()')[-1]
self.db.add_new_row('mingJuSpider', {'content': content, 'origin': origin, 'createTime': str(date.today())})
三. 执行结果
四. 脚本源码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Date : 2017/12/21 12:35
@Author : kaiqing.huang
@File : mingJuSpider.py
'''
from utils import MySpider, MongoBase
from datetime import date
from lxml import etree
import sys
class mingJuSpider():
def __init__(self):
self.db = MongoBase()
self.spider = MySpider()
def download(self):
for pageId in range(1,117):
url = 'http://so.gushiwen.org/mingju/Default.aspx?p={}&c=&t='.format(pageId)
print url
data = self.spider.get(url)
if data:
self.parse(data)
def parse(self, data):
response = etree.HTML(data)
for row in response.xpath('//div[@class="left"]/div[@class="sons"]/div[@class="cont"]'):
content = row.xpath('a/text()')[0]
origin = row.xpath('a/text()')[-1]
self.db.add_new_row('mingJuSpider', {'content': content, 'origin': origin, 'createTime': str(date.today())})
if __name__ == '__main__':
sys.setrecursionlimit(100000)
do = mingJuSpider()
do.download()
python输出古诗词_python爬虫——爬取古诗名句相关推荐
- python输出古诗词_python爬虫——爬取古诗词
一. 概要 1.通过python爬虫循环爬取古诗词网站唐诗宋词 2.落地到本地数据库 二. 页面分析 首先通过firedebug进行页面定位: 其次源码定位: 最终生成lxml etree定位div标 ...
- python爬虫——爬取古诗名句
一. 概要 1.通过python爬虫循环爬取古诗词网站古诗名句 2.落地到本地数据库 二. 页面分析 首先通过firedebug进行页面定位: 其次源码定位: 最终生成lxml etree定位div标 ...
- python xpath循环_Python爬虫 爬取北京二手房数据
点击蓝字"python教程"关注我们哟! 前言 Python现在非常火,语法简单而且功能强大,很多同学都想学Python!所以小的给各位看官们准备了高价值Python学习视频教程及 ...
- python搞笑教程_python爬虫- 爬取幽默笑话网站,带你一起笑翻天
importrequestsimportthreadpoolimporttimeimportos,sysimportrefrom lxml importetreefrom lxml.html impo ...
- python爬虫提取人名_python爬虫—爬取英文名以及正则表达式的介绍
python爬虫-爬取英文名以及正则表达式的介绍 爬取英文名: 一. 爬虫模块详细设计 (1)整体思路 对于本次爬取英文名数据的爬虫实现,我的思路是先将A-Z所有英文名的连接爬取出来,保存在一个csv ...
- python跑一亿次循环_python爬虫爬取微博评论
原标题:python爬虫爬取微博评论 python爬虫是程序员们一定会掌握的知识,练习python爬虫时,很多人会选择爬取微博练手.python爬虫微博根据微博存在于不同媒介上,所爬取的难度有差异,无 ...
- python爬虫网页中的图片_Python爬虫爬取一个网页上的图片地址实例代码
本文实例主要是实现爬取一个网页上的图片地址,具体如下. 读取一个网页的源代码: import urllib.request def getHtml(url): html=urllib.request. ...
- python爬表格数据_python爬虫,爬取表格数据
python爬虫,爬取表格数据 python爬虫,爬取表格数据 python爬虫,爬取全国空气质量指数 编程环境:Jupyter Notebook 所要爬取的网页数据内容如下图 python爬虫代码及 ...
- python爬去新浪微博_Python爬虫爬取新浪微博内容示例【基于代理IP】
Python爬虫爬取新浪微博内容示例[基于代理IP] 发布时间:2020-09-07 10:08:14 来源:脚本之家 阅读:120 本文实例讲述了Python爬虫爬取新浪微博内容.分享给大家供大家参 ...
最新文章
- 025 使用@Profile完成环境条件注入
- UVa 10026 - Shoemaker's Problem
- mssql 将查询结果作为表名参数_MySQL·查询(一)
- tableau两个不同的图合并_【书稿摘要】Tableau地图函数(下)
- Web前端开发规范之图片命名规范
- 在Ubuntu-16.04安装Chrome、搜狗拼音输入法、网易云音乐
- 上帝掷骰子吗--量子物理史话
- 李炎恢PHP培训视频教程
- 《指数型组织》学习总结
- 8 款免费的 MySQL 数据库建模工具
- 物联网操作系统的概念和特点
- android studio logcat 字体,android studio - 修改logcat颜色字体
- [024] 欢迎大家关注我的微信公众帐号小q机器人(xiaoqrobot)
- 伦敦金走势图与顾比均线
- 实战案例!用 Python 绘制全国鸿星尔克门店分布图,最多的是你所在城市吗?
- 常用URL分享,实用地址
- Fabric 节点类型&交易流程
- 计算机系微电子专业就业前景,2019微电子技术专业就业前景和就业方向分析
- 旧金山大学数据结构和算法的可视化工具
- Web笔记(二)Tomcat 使用总结