Я анализирую страницу, у которой есть 20 ссылок на следующую страницу.Вот так: 
Но у одного из них нет href

Это вызовет мой кодошибка.
i = 1000
j = 0
dataLen = len(response.xpath('//div[@class="rank_list table rankstyle1"]//div[@class="tr"]'))
photoNodes = response.xpath('//div[@class="rank_list table rankstyle1"]//div[@class="tr"]')
for photoNode in photoNodes:
contentHref = photoNode.xpath('.//a/@href').extract_first()
yield Request(contentHref, callback=self.parse_page, priority = i, dont_filter=True)
i -= 1
j += 1
# start parse next page
def parse_page(self, response):
global countLen, dataLen
enName = response.xpath('//*[@class="movie_intro_info_r"]/h3/text()').extract_first()
cnName = response.xpath('//*[@class="movie_intro_info_r"]/h1/text()'
...
Я пытаюсь добавить if not (photoNode is None):
или if not photoNode ==""
, все еще не работающий.
i = 1000
j = 0
dataLen = len(response.xpath('//div[@class="rank_list table rankstyle1"]//div[@class="tr"]'))
photoNodes = response.xpath('//div[@class="rank_list table rankstyle1"]//div[@class="tr"]')
for photoNode in photoNodes:
if not (photoNode is None):
contentHref = photoNode.xpath('.//a/@href').extract_first()
# photoHref = photoNode.xpath('.//a/img/@src').extract_first()
yield Request(contentHref, callback=self.parse_page, priority = i, dont_filter=True)
i -= 1
j += 1
else:
pass
twRanking['movie'] = movieArray
Я понятия не имею, как его пропустить, если он может не иметь href
.
Буду признателен за любую помощь.Заранее спасибо.