【发布时间】:2020-08-29 17:51:22
【问题描述】:
我正在抓取 JSON 响应,但收到以下错误
values = resp['acf']
TypeError: list indices must be integers or slices, not str
我不知道我哪里做错了。 非常感谢您的回复。
# -*- coding: utf-8 -*-
import scrapy
import json
class MainSpider(scrapy.Spider):
name = 'main'
start_urls = 'https://chamber.vinylagency.com/wp-json/wp/v2/directory?industry-type=547&per_page=100'
def parse(self, response):
resp = json.loads(response.body)
values = resp['acf']
for value in values:
name = value['OrgName']
yield {
"Name": name,
}
【问题讨论】: