scrapy xpath取包含某些特定文字的选择器,获取一个标签下的所有text(包括自身和子孙)

来源:互联网 发布:js获取div的id值 编辑:程序博客网 时间:2024/05/18 03:52

http://blog.scrapinghub.com/2014/07/17/xpath-tips-from-the-web-scraping-trenches/


scrapy 

获取一个标签下的所有text(包括自身和子孙)

products = re.sub("\n", ",", response.css(".Products_td").xpath("string(div)").extract_first(default = "").strip()) #用string或就可以将div这个标签下的所有文字取出来


包含某些特定文字的选择器

response.xpath("//li[contains(span/text(), 'Location')]/div/text()").extract_first(default = "")  #选择一个li,其下的span的文字中包含Location,把这个li下的div中的文字取出来


not contains

http://stackoverflow.com/questions/28163626/xpath-not-contains-a-and-b 

0 0
原创粉丝点击