前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >爬虫练习--草稿

爬虫练习--草稿

作者头像
热心的社会主义接班人
发布2018-05-16 15:49:54
9130
发布2018-05-16 15:49:54
举报
文章被收录于专栏:cscs

简书的robots

代码语言:javascript
复制
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
User-agent: *
Disallow: /search
Disallow: /convos/
Disallow: /notes/
Disallow: /admin/
Disallow: /adm/
Disallow: /p/0826cf4692f9
Disallow: /p/d8b31d20a867
Disallow: /collections/*/recommended_authors
Disallow: /trial/*
Disallow: /keyword_notes
Disallow: /stats-2017/*

User-agent: trendkite-akashic-crawler
Request-rate: 1/2 # load 1 page per 2 seconds
Crawl-delay: 60

User-agent: YisouSpider
Request-rate: 1/10 # load 1 page per 2 seconds
Crawl-delay: 60

User-agent: Cliqzbot
Disallow: /

User-agent: Googlebot
Request-rate: 1/1 # load 1 page per 2 seconds
Crawl-delay: 10
代码语言:javascript
复制
mport urllib.request
import urllib.parse
import re

url="https://www.jianshu.com/c/bd38bd199ec6"
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/52.0.2743.116 Safari/537.36')
response=urllib.request.urlopen(req)
html=response.read().decode("utf-8")
#print(html)

pattern=re.compile(r'<p class="abstract">\s+(.*)\s+</p>')


result=re.findall(pattern,html)



#for each in result:
#    print(each)
#print(result)
    
print("the length=============",len(result))

print("----------------",result[1])

print("*******",len(result[1]))

爬虫.png

模仿:Python爬虫初学(一)—— 爬取段子

还有事情年,还有许多东西需要修改,比如把交友文章下载下来,或者爬取图片,等等什么的. re表达式,我还不是很熟。

代码语言:javascript
复制
<a class="nickname" target="_blank" href="[/u/1195c9b43c46](view-source:https://www.jianshu.com/u/1195c9b43c46)">
大大懒鱼</a>  
<span class="time" data-shared-at="2018-04-26T21:15:25+08:00">
</span> 
 <a class="title" target="_blank" href="[/p/a1d691ab1111](view-source:https://www.jianshu.com/p/a1d691ab1111)">
【简书交友】大大懒鱼:爱好服装搭配的特别能吃麻辣中年少女</a>

这些regular,我还必须写出来,以及翻叶等。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.04.27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档