爬取简书标题和摘要
来源:互联网 发布:react用js和jsx的区别 编辑:程序博客网 时间:2024/06/15 12:11
有些小瑕疵不知道为啥爬取的标题个数与摘要个数不是整个页面的,而且两者也不相等,不过是第一次做出来,简单记录一下啦~~~~
import urllib.requestimport reimport osdef url_open(url): req=urllib.request.Request(url) req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36') response=urllib.request.urlopen(url) html=response.read().decode('utf-8') return htmldef get_title(html): p=r'<a.*?class="title".*?target="_blank".*?href=".*?">(.*?)</a>' t=r'<p.*?class="abstract">(.*?)</p>' titlelist=re.findall(p,html,re.S) abstractlist=re.findall(t,html,re.S) ''' for each in titlelist: print(each) for each in abstractlist: print(each) ''' i=len(titlelist) with open(r'essay.txt','w') as f: for x in range(i-1): f.write(str(x+1)+titlelist[x]+'\n'+abstractlist[x]+'\n')if __name__=='__main__': os.mkdir("E:\Title") os.chdir("E:\Title") url='http://www.jianshu.com/' get_title(url_open(url))
阅读全文
0 0
- 爬取简书标题和摘要
- 策划书标准和重点
- 高仿小红书标签的添加和回显
- 字段摘要和方法摘要
- 调试方法和摘要
- android自定义view-仿小红书标签
- ADO.NET链接和摘要
- 怎样写摘要和引言
- Protobuf使用摘要和demo
- ReviewBoard安装和配置摘要
- Protobuf使用摘要和demo
- sscanf和scanf用法摘要
- 经典算法题摘要
- 摘要
- 摘要
- 摘要
- 摘要
- 摘要
- Mybatis-Generator配置使用方法
- R中的字符处理函数汇总
- 微信开发篇章1 授权
- Codeforces Round #453 (Div. 2) B
- Oracle(一)下
- 爬取简书标题和摘要
- ACE_Service_Handler类的理解和使用
- Ubuntu 16.04 安装 PyCharm
- 在mysql中使用去重distinct需要注意的
- ServerSocket用法
- The record for a starter making a printed circuit board.
- 微服务:微服务架构模式译文说明
- Leetcode 89. Gray Code
- 最短路径