I've written this very short spider to go to a U.S. News link and take the names of the colleges listed there.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import scrapy
class CollegesSpider(scrapy.Spider):
name = "colleges"
start_urls = [
'http://colleges.usnews.rankingsandreviews.com/best-colleges/rankings/national-universities?_mode=list&acceptance-rate-max=20'
]
def parse(self, response):
for school in response.css('div.items'):
yield {
'name': school.xpath('//*[@id="view-1c4ddd8a-8b04-4c93-8b68-9b7b4e5d8969"]/div/div[1]/div[1]/h3/a').extract_first(),
}
However, when I run this spider and ask for the names to be stored in a file named schools.json, the file comes out blank. What am I doing wrong?