极客都是这么看小说
- 代码为本人原创,且仅限于学习交流,请勿用于任何商业用途!本人不承担任何法律责任,如果涉及到侵权问题,请留言告知。
import requests
from bs4 import BeautifulSoup
class downloader(object):
def __init__(self):
self.base = 'http://m.yruan.com'
self.article = '/article/53567/'
self.page = '26602528.html'
self.target = self.base + self.article + self.page
def get_contents(self):
req = requests.get(url=self.target)
req.encoding = 'utf-8'
html = req.text
bs = BeautifulSoup(html, 'html.parser')
novelcontent = bs.find(name='div', id="novelcontent")
print(type(novelcontent))
print(novelcontent.find(name='p').text.replace('\n\n', '\n'))
next_a = novelcontent.find(name='ul', class_='novelbutton').find(name='p', class_='p1 p3').find(name='a')
print(next_a.get('href'))
print("current_url: " + self.target)
return self.base + next_a.get('href')
if __name__ == '__main__':
dl = downloader()
next_url = dl.get_contents()
print("Next_url: " + next_url)