1 #-*-coding:utf-8-*- 2 import re
#导入正则表达式模块 3 import urllib
#导入urllib库 4 5 url=''
#第一页博文地址
6 response= urllib.urlopen(url)
#通过urllib库中的urlopen()函数来访问这个url
#这里省略了构建request请求这一步
7 html=response.read()
#读取出来存在html这个变量当中,到这里也就完成了html的爬取
8 #print(html) 9 #这里可以将爬取到的html输出到终端 10 pattern=re.compile('(.*?)',re.S)
#通过正则表达式来匹配 11 blog_address= re.findall(pattern,html)
#通过findall函数从爬取到的html中找出所要的内容 12 for i in blog_address: 13 print(i[0])
#输出第一个分组的内容即博客博文地址 14 print(i[1])
#输出第二个分组的内容即博文标题
python爬虫-韩寒新浪博客博文
作者:python爬虫-韩寒新浪博客博文 来源:未知 2022-06-20 23:56 阅读:次
1#-*-coding:utf-8-*-2importre#导入正则表达式模块3importurllib#导入urllib库45url=''#第一页博文地址6response=ur
