Em đang làm một crawler của trang Imdb-glossary và sử dụng framework Scrapy nhưng khi e khi chạy trên powershell bị lỗi.Bác nào biết xin fix giùm e ạ
import scrapy
from scrapy.spiders import CrawlSpider
from glossary.items import GlossaryItem
class glossary(scrapy.Spider):
name = "glossary"
allowed_domains = ["imdb.com"]
start_urls = [
"http://www.imdb.com/glossary/"
]
def parse(self, response):
for sel in response.xpath("//*[@id='pagecontent']/table/tbody/tr"):
item = GlossaryItem()
item['ItemGlossary'] = sel.xpath("td[2]/a/text()").extract()[0]
item['MainPageUrl'] = "http://imdb.com/glossary/"+sel.xpath("td[@class='lhsef']/a/@href").extract()[0]
#request = scrapy.Request(item['MainPageUrl'], callback=self.)
request = scrapy.Request(item['MainPageUrl'], callback=self.parse_glossary)
yield request
def parse_glossary(self, item, response):
item ['Title'] = response.xpath("//table/tbody/tr/td[3]/h1/text()").extract()[0]
for content in response.xpath("//table/tbody/tr/td[3]/h3"):
item['Content'] = content.xpath("a/text()").extract()[0]
return item