我试图查看商家名称是否与之前的商家名称匹配,是否确实打破了迭代,如果没有继续迭代。
问题
它忽略了休息,我仍然看到重复。
run.py
def parse(self, response):
for business in response.css('div.info'):
business_names = business.css('span[itemprop="name"]::text').extract()
business_name = business.css('span[itemprop="name"]::text').extract()
if business_name in business_names:
break
else:
website = business.css('div.links a::attr(href)').extract_first()
phone_number = business.css('div.phones.phone.primary::text').extract()
yield {
'Business Name': business_names,
'Website': website,
'Phone Number': phone_number,
}
答案 0 :(得分:0)
使用in
运算符检查是否存在,并为项目设置一些值。现在,您的代码正在检查business_name
的元素是否等于business_name
for item in business_name:
if item == business_name:
break
要:
if 'somevaluehere' in business_names:
break