本次我们是通过漫画的id进行漫画爬取,所以我们不需要再做搜索的那种形式了
通过审查元素我们可以发现,所有的章节链接都是通过一个ol的标签进行包裹,所以我们只要获取要页面中的一个ol标签下,所有的a链接就可以成功的获取到所有的章节链接了。
代码如下:
新手学习,Python 教程/工具/方法/解疑+V:itz992
#获取漫画的章节地址
def get_chapter_info(self):
chapter_info = {}
url = 'http://ac.qq.com/Comic/ComicInfo/id/{}'.format(self.comic_id)
html_text = self.get_html(url)
html = self.parser(html_text) # 找到所有章节列表
ol = html.find('ol')[0]
chapters = ol.find('a')
index = 0 for chapter in chapters:
title = chapter.attrs['title']
link = parse.urljoin(TxComic.COMIC_HOST, chapter.attrs['href'])
key = '第{}章'.format(index)
chapter_info[key] = {'title': title, 'link': link}