[英]How do I use scrapy re() selector?
這是我的正則表達式:
".*\/(.*)\?ref"
這是我的測試字符串:
/product/sam/go-with-me?ref=popular
我可以得到: go-with-me
我確實嘗試過https://regex101.com/#python
但是我不知道怎么寫
這是我的代碼:
for site in sites:
title = sel.css("a::text").re(r".*\/(.*)\?ref")
print title
break
沒有看到真正的HTML輸入數據很難說,但是您可能只需要查看href
屬性值而不是文本即可:
for site in sites:
title = site.xpath(".//a/@href").re(r".*\/(.*)\?ref")
print title
break
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.