modify class attrib selector

This commit is contained in:
cooper 2024-05-20 14:21:34 +08:00
parent d1e3d99a76
commit dc35f3f990

View File

@ -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'] = '北极星太阳能光伏网'