2019-03-26学习笔记 报错的解决方法+技术选型问题

2019-03-26  本文已影响0人  loonytes

【环境配置】出现:Microsoft Visual C++ 14.0 is required 的解决方案
如:pip install scrapy 时出现:

错误信息

error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools
说明计算机中缺少Microsoft Visual C++ 14.0
但错误信息中提供的网址是无效的,需要自行从网络中下载安装MV C++14.0

可以使用以下链接进行下载安装:
链接:https://pan.baidu.com/s/1G7DomtDZG0GpgSVZXloscw
提取码:ik9k

技术选型:

网页分类:

  1. 静态页面
  2. 动态页面
  3. webservices(restapi)

爬虫能做什么:

正则表达式:

出现问题:pycharm授权账户过期
建议更新账户后下载离线激活码使用


下载离线激活码
  1. 新建python工程
  2. 新建的python工程使用虚拟环境,在创建时会自动下载安装setuptools,pip,wheel等
  3. 在工程下新建名为“test”的pythonpackage的文件


    新建py工程与py文件

特殊字符

1. 匹配以b开头,后面为任意字符

import re #使用正则表达式的包

line="booby123"
regex_str="^b.*"
if re.match(regex_str,line): #re.match()是re包中的模块
    print("yes")

2.使用?克服贪婪匹配

import re

line="boooooobby123"
regex_str=".*(b.*b).*" #提取括号中的内容
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

输出结果为:bb

贪婪匹配:正则表达式一般趋向于最大长度匹配,也就是所谓的贪婪匹配。
非贪婪匹配:就是匹配到结果就好,就少的匹配字符。

当两侧都无?控制的情况下,类似于反向匹配,即从右侧开始匹配(如上所示)
当左侧有?控制且右侧无?控制的情况下,则从左侧开始匹配得到最长的结果为止(如下所示)

import re

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

输出结果为boooooobb

正确表达式应为

import re

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

3.使用+的实例

import re

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

结果:bb

import re

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

结果:bnnvccbb
4.使用{}的实例

import re

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

结果:bab

import re

line="boooooobnnvccbaaaby123"
regex_str=".*(b.{1,3}b).*"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:baaab
5.使用|的实例

import re

line="booby123"
regex_str="(booby|booby123)"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:booby
6.使用[]的实例

import re

line="booby123"
regex_str="([abcd]ooby123)"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:booby123
7.使用[0-9]的实例

import re

line="15764289384"
regex_str="(1[3578][0-9]{9})"
#第一位数字为1,第二位数字为3 5 7 8 中的任意一个,之后为9个0-9之间的字符
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:15764289384

8. 使用\s\S的实例

import re

line="你 好"
regex_str="(你\s好)"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:你 好

import re

line="你很不好"
regex_str="(你\S+好)"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:你很不好

9. 使用\w\W的实例

import re

line="你S好"
regex_str="(你\w好)"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:你S好

10. 使用[\u4E00-\u9FA5]的实例

import re

line="你 好"
regex_str="([\u4E00-\u9FA5]+)"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:你

import re

line="stydy in 南京大学"
regex_str=".*?([\u4E00-\u9FA5]+大学)"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:南京大学

11.使用\d的实例

import re

line="XXX出生于2001年"
regex_str=".*?(\d+)年"
match_obj=re.match(regex_str,line)
if match_obj:
    print(match_obj.group(1))

结果:2001年

正则表达式练习

匹配不同的出生日期写法:

import re

#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))
上一篇 下一篇

猜你喜欢

热点阅读