执行py文件前,需要先安装这2个包
pip install beautifulsoup4
pip install requests
#!/usr/bin/env python3.7
# -*- coding: utf-8 -*
# author by slo
from bs4 import BeautifulSoup
import requests
class DownLoader(object):
def __init__(self):
self.url = 'http://www.17k.com'
# 这里是你要下载的小说目录页
self.target = 'http://www.17k.com/list/349579.html'
# 存储小说的章节
self.names = []
# 存储小说相应章节的url地址
self.urls = []
# 存储下载的章节数
self.nums = []
# 获取下载链接
def get_download_url(self):
html = requests.get(url=self.target).content.decode('utf-8')
soup