我调用了re.match,但错误表明该列表需要一个整数而不是字符串。
tripadvisor_item['avg_stars'] = re.match(r'(\S+)', snode_restaurant_item_avg
_stars).group()
TypeError: list indices must be integers, not str
这是代码,
# Build item index.
for snode_restaurant in snode_restaurants:
# Cleaning string and taking only the first part before whitespace.
snode_restaurant_item_avg_stars = clean_parsed_string(get_parsed_string(snode_restaurant, 'div[@class="wrap"]/div[@class="entry wrap"]/div[@class="description"]/div[@class="wrap"]/div[@class="rs rating"]/span[starts-with(@class, "rate")]/img[@class="sprite-ratings"]/@alt'))
tripadvisor_item['avg_stars'] = re.match(r'(\S+)', snode_restaurant_item_avg_stars).group()*
# Popolate reviews and address for current item.
yield Request(url=tripadvisor_item['url'], meta={'tripadvisor_item': tripadvisor_item}, callback=self.parse_fetch_review)
即使在文档中也是如此,
"""Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found."""