python - Scrapy正则表达式怎么去掉空格和换行符?
伊谢尔伦
伊谢尔伦 2017-04-18 10:07:54
0
1
1417
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
大家讲道理

You can use the re.sub function to perform regular replacement,
sub(pattern, repl, string, count=0)

  • First parameter: Rule

  • The second parameter: the replaced string

  • The third parameter: string

  • The fourth parameter: the number of replacements. Defaults to 0, meaning every match is replaced

>>> a="\t\t\n 123"
>>> a
'\t\t\n 123'
>>> b = re.sub(r'\s+','', a) #\s   匹配任意的空白符
>>> b
'123'
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template