Home  >  Q&A  >  body text

python - 正则表达式匹配“\xa0”的问题

伊谢尔伦伊谢尔伦2717 days ago385

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 10:12:04

    Use strip() to remove leading and trailing spaces

    from scrapy.selector import Selector
    
    content = "<p>数量:100-200个&nbsp;&nbsp;&nbsp;&nbsp;</p>"
    strings = Selector(text=content).xpath('//p/text()').re_first(u'数量:(.+)\s$').strip()
    print(strings)
    print(len(strings))
    """
    100-200个
    8
    """
    

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:12:04

    '数量:(S+)'

    reply
    0
  • Cancelreply