diff --git a/newsspider/spiders/bjxpv.py b/newsspider/spiders/bjxpv.py index 059f0a2..c839399 100644 --- a/newsspider/spiders/bjxpv.py +++ b/newsspider/spiders/bjxpv.py @@ -14,11 +14,10 @@ class BjxpvSpider(scrapy.Spider): yield scrapy.Request(url, self.news_parse) next_page = response.xpath('//a[contains(text(), "下一页")]') - if next_page.attrib['class'] != 'disable': + if next_page.attrib.get('class') != 'disable': url = next_page.attrib['href'] yield response.follow(url, self.parse) - def news_parse(self, response): news_item = NewsItem() news_item['website'] = '北极星太阳能光伏网'