当我执行此代码时,我的结果形式为{[text1,author1,tag1],[text2,author2,tag2],...}
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = [
'http://quotes.toscrape.com/page/1/',
]
def parse(self, response):
for quote in response.css('div.quote'):
yield {
'text': quote.css('span.text::text').extract_first(),
'author': quote.css('small.author::text').extract_first(),
'tags': quote.css('div.tags a.tag::text').extract(),
}
但是,在另一个网址(下面)的相同代码中,我得到的结果为{[name1,name2,..],[city1,city2,...]} 我希望以{[name1,city1],[name2,city2],...]的形式提供它,因为它发生在上面的代码中。
import scrapy
class QuotesSpider(scrapy.Spider):
name = "student"
start_urls = [
'http://www.engineering.careers360.com/colleges/list-of-engineering-colleges-in-karnataka?sort_filter=alpha',
]
def parse(self, response):
for students in response.css('div.list-pages'):
yield {
'name': students.css('div.title a::text').extract(),
'city': students.css('div.clg-state a::text').extract(),
}
答案 0 :(得分:0)
您的学生选择器有问题:
for students in response.css('div.list-pages'):
这只选择整页 你在这里寻找的是我认为:
for students in response.css('li.search-result'):