|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import re
import requests
#获取网页源代码,并且转化为中文
response=requests.get('http://www.jianlaixiaoshuo.com/')
response.encoding='utf-8'
html=response.text
#提取全部章节的url和标题
dl=re.findall(r'<dl class="chapterlist">.*?</dl>',html,re.S)[0]
#提取出所需的每一章节的url和每一章节的标题
chapter_list=re.findall(r'<dd><a href="(.*?)"target="_blank">(.*?)</a></dd>',dl)
print(chapter_list)
为什么print(chapter_list)打印出来的是空[]列表。
但是如果我换成:
import re
import requests
#获取网页源代码,并且转化为中文
response=requests.get('http://www.jianlaixiaoshuo.com/')
response.encoding='utf-8'
html=response.text
#提取全部章节的url和标题
dl=re.findall(r'<dl class="chapterlist">.*?</dl>',html,re.S)[0]
#提取出所需的每一章节的url和每一章节的标题
href=re.findall(r'href="(.*?)" ',dl)
print(href)
就能打印出来url
|
|