Parse Xpath from Int

0

I have a scrapy running the for to bring the day and the link to something. Ex:

t_day = div.xpath('.//a/text()').extract_first()
a_day = div.xpath('.//a/@href').extract_first()
day = int(t_day)
if day > last_day:
    print(t_day, a_day)

And in execution it returns the error:

in parse
day = int(t_day)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

What do I need to do to resolve the issue?

    
asked by anonymous 04.05.2018 / 20:57

1 answer

0

This error happens because the value of the variable t_day is null, you can use an if ternary to solve the problem, returning a default value if the variable is null.

int(0 if a is None else t_day)
    
07.05.2018 / 15:36