资源简介
自己练手的代码,爬虫小程序,爬一些鬼故事。。。自己练手的代码,爬虫小程序,爬一些鬼故事。。。自己练手的代码,爬虫小程序,爬一些鬼故事。。。自己练手的代码,爬虫小程序,爬一些鬼故事。。。
代码片段和文件信息
import requests
from lxml import etree
import pymysql
import time
class kunbubooks(object):
def __init__(self):
# self.URL = “http://www.bestgushi.com/o/kongbu/index.html“
self.headers = {‘User-Agent‘:‘Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)‘}
# 创建数据库连接对象与游标对象
# self.db = pymysql.connect(‘localhost‘
# ‘root‘
# ‘123456‘
# ‘gushi‘
# charset=‘utf8‘)
# self.cursor = self.db.cursor()
def bookurllist(selfURL):
# 请求三步
res = requests.get(URLheaders=self.headers)
res.encoding = ‘gbk‘
html = res.text
parseHtml = etree.HTML(html)
# 找出一页中所有故事的链接
books = parseHtml.xpath(“//div[@class=‘gs‘]/h3/a/@href|//div[@class=‘gs yt‘]/h3/a/@href“)
for b in books:
self.book(b) #循环遍历每个故事链接,调用并交给book函数
def book(selfb):
res = requests.get(bheaders=self.headers)
res.encoding = ‘gbk‘ #文中有些是gb2312解不出来的,所以要用到gbk
html = res.text
parseHtml = etree.HTML(html)
book = parseHtml.xpath(“//div[@id=‘zzzxcwqsdas‘]//p//text()“) #得到故事内容列表
bookname = parseHtml.xpath(“//div[@class=‘gushi‘]/h1/a/text()“) #得到故事名
for x in range(250):
y = b[:-5] + ‘_‘ + str(x) + ‘.html‘ #拼接每个故事页面中的分页链接
# 循环请求分页链接
res1 = requests
相关资源
- 易语言python支持库
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 一个多线程智能爬虫,爬取网站小说
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- 顶点小说单本书爬虫.py
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
评论
共有 条评论