美文网首页
爬虫(3-1 3-2)

爬虫(3-1 3-2)

作者: buaishengqi | 来源:发表于2018-07-03 19:01 被阅读193次

3-1 爬虫技术选型,爬虫能做什么?
技术选型:
scrapy vs requests+beautifulsoup
1.requests和beautifulsoup都是库,scrapy是框架
2。scrapy框架中可以加入requests和beautifulsoup
3.scrapy基于twisted,性能是最大的优势
4.scrapy方便扩展,提供了很多内置功能
5。scrapy内置的css和xpath selector非常方便,beautifulsoup最大的缺点就是慢

网页分类:
常见类型的服务:
1.静态网页
2.动态网页
3.weservice(restapi)

爬虫能做什么?
爬虫的作用:
1.搜索引擎
2。推荐引擎
3.机器去学习的样本
4.数据分析

3-2 正则表达式
正则表达式介绍
1.为什么必须会正则表达式
2.正则表达式的简单应用和Python实例

正则表达式
目录
1字符串

'''
import re

line = "bobby123"
regex_str = "^b."
if re.match(regex_str,line):
    print("yes")



import re

line = "bobby123"
regex_str = "^b.4$"
if re.match(regex_str,line):
    print("yes")



import re

line = "boooooooooobby123"
regex_str = ".*(b.*b).*"
match_obj = re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))


import re

line = "boooooooooobby123"
regex_str = ".*?(b.*b).*"
match_obj = re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))
'''

import re

line = "xxx出生于2001年6月1日"
line = "xxx出生于2001/6/1"
line = "xxx出生于2001-6-1"
#line = "xxx出生于2001-06-01"
#line = "xxx出生于2001-06"

regex_str = ".*出生于(\d{4}[年/-]\d{1,2}([月/-]\d{1,2}|[月/-]$|$))"
match_obj = re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

相关文章

网友评论

      本文标题:爬虫(3-1 3-2)

      本文链接:https://www.haomeiwen.com/subject/podruftx.html