使用requests+BeautifulSoup爬取龙族V小说
这几天想看龙族最新版本,但是搜索半天发现 没有网站提供 下载, 我又只想下载后离线阅读(写代码已经很费眼睛了)。无奈只有自己 爬取了。
这里记录一下,以后想看时,直接运行脚本 下载小说。
这里是从 http://longzu5.co 这个网站下载的小说,如果需要更改存储路径,可以更改 FILE_URL 常量的值
如果 爬取不到了,说明,此网站做了防爬虫,或者 其渲染 网页的 html 元素改变了。
# -*- coding: utf-8 -*-
# (C) rgc, 2018
# All rights reserved
# requirements list: [python3.6, requests, bs4] import requests
from bs4 import BeautifulSoup URL = "http://longzu5.co"
FILE_URL = 'E:\lz.txt' def get_son_text(strs):
# 获取文章内容
soup = BeautifulSoup(strs, 'html.parser')
body_soup = soup.find('div', 'post-body')
result = body_soup.find_all('p')
title = soup.find('h2', 'post-title')
title = title.text
final_txt = title + '\n' for item in result:
txt = item.text
final_txt += txt
final_txt += '\n\n'
with open(FILE_URL, 'a', encoding='utf-8') as f:
f.write(final_txt) def get_father_text():
"""
获取文章列表
:return:
"""
res = requests.get(URL + "/")
strs = res.text
soup = BeautifulSoup(strs, 'html.parser') ul_soup = soup.find('ul', 'booklist')
x = ul_soup.find_all('a')
section_list = []
for item in x:
url = URL + item.get('href')
section_list.append(url) section_list.reverse()
for url in section_list:
print(url)
section = requests.get(url)
sec_txt = section.text
get_son_text(sec_txt) if __name__ == '__main__':
get_father_text()
# 如有版权,请及时联系我,我会及时删除,如有冒犯,请原谅。
使用requests+BeautifulSoup爬取龙族V小说的更多相关文章
- 爬虫入门实例:利用requests库爬取笔趣小说网
w3cschool上的来练练手,爬取笔趣看小说http://www.biqukan.com/, 爬取<凡人修仙传仙界篇>的所有章节 1.利用requests访问目标网址,使用了get方法 ...
- python3 requests + BeautifulSoup 爬取阳光网投诉贴详情实例代码
用到了requests.BeautifulSoup.urllib等,具体代码如下. # -*- coding: utf-8 -*- """ Created on Sat ...
- python 爬虫 requests+BeautifulSoup 爬取巨潮资讯公司概况代码实例
第一次写一个算是比较完整的爬虫,自我感觉极差啊,代码low,效率差,也没有保存到本地文件或者数据库,强行使用了一波多线程导致数据顺序发生了变化... 贴在这里,引以为戒吧. # -*- coding: ...
- requests+BeautifulSoup | 爬取电影天堂全站电影资源
import requests import urllib.request as ur from bs4 import BeautifulSoup import csv import threadin ...
- Python爬虫学习三------requests+BeautifulSoup爬取简单网页
第一次第一次用MarkDown来写博客,先试试效果吧! 昨天2018俄罗斯世界杯拉开了大幕,作为一个伪球迷,当然也得为世界杯做出一点贡献啦. 于是今天就编写了一个爬虫程序将腾讯新闻下世界杯专题的相关新 ...
- python 爬虫(一) requests+BeautifulSoup 爬取简单网页代码示例
以前搞偷偷摸摸的事,不对,是搞爬虫都是用urllib,不过真的是很麻烦,下面就使用requests + BeautifulSoup 爬爬简单的网页. 详细介绍都在代码中注释了,大家可以参阅. # -* ...
- requests+beautifulsoup爬取豆瓣图书
使用Xpath和BeautifulSoup来解析网页可以说真的很简便. import requests from bs4 import BeautifulSoup from random import ...
- Python使用urllib,urllib3,requests库+beautifulsoup爬取网页
Python使用urllib/urllib3/requests库+beautifulsoup爬取网页 urllib urllib3 requests 笔者在爬取时遇到的问题 1.结果不全 2.'抓取失 ...
- [实战演练]python3使用requests模块爬取页面内容
本文摘要: 1.安装pip 2.安装requests模块 3.安装beautifulsoup4 4.requests模块浅析 + 发送请求 + 传递URL参数 + 响应内容 + 获取网页编码 + 获取 ...
随机推荐
- [LeetCode&Python] Problem 704. Binary Search
Given a sorted (in ascending order) integer array nums of n elements and a target value, write a fun ...
- 联想Y410P在Ubuntu系统下开关机及插耳机破音“啪啪”的解决办法
转载自:https://blog.csdn.net/YiKangJ/article/details/81239556 1.解决开关机“啪啪响”: options snd-hda-intel model ...
- 测试那些事儿—selenium IDE 自动化测试
浏览器 Firefox Setup 35.0.1 安装完成后设置菜单栏 关闭浏览器自动更新 插件配置(必备武器) FireBug Firebug是firefox下的一个扩展,能够调试所有网站语言,如H ...
- flutter 添加插件
打開pubspec.yaml ---> cupertino_icons 下添加插件
- maven各个属性参数详解
<project xmlns="http://maven.apache.org/POM/4.0.0 " xmlns:xsi="http://www.w3.org/2 ...
- window.location各属性的值
window.location各属性的值 window.location.href "https://i.cnblogs.com/EditPosts.aspx?opt= ...
- 自动化测试_Mac安装python+selenium
1.下载安装(参照下文) https://blog.csdn.net/kacylining/article/details/60587484 https://www.zhihu.com/questio ...
- 1ubuntu安装虚拟机
安装相关打软件:(qemu-kvm qemu-system是kvm和qemu的核心包,libvirt-bin用于管理kvm,virt-manager图形管理工具,bridge-utils vlan,主 ...
- 兄弟连学python---网络简介
网络简介 1.什么是网络 网络是辅助双方能够连接在一起的工具 使用网络的目的 为了联通多方然后进行通讯,能够让软件在不同的电脑上运行,相互传输数据 网络的发展 网络协议 什么是协议 约定俗成的,没有理 ...
- ssm项目整合shiro
pom.xml <properties> <shiro.version>1.2.2</shiro.version> </properties> < ...