Extract class name in scrapy

前端 未结 3 2040
粉色の甜心
粉色の甜心 2021-01-19 11:41

I am trying to scrape rating off of trustpilot.com.

Is it possible to extract a class name using scrapy? I am trying to scrape a rating which is made up of five indi

3条回答
  •  长发绾君心
    2021-01-19 12:10

    You could use a combination of both somewhere in your code:

    import re
    
    classes = response.css('.star-rating').xpath("@class").extract()
    for cls in classes:
        match = re.search(r'\bcount-\d+\b', cls)
        if match:
            print("Class = {}".format(match.group(0))
    

提交回复
热议问题