Scrapy:ValueError: invalid literal for int() with base 10: ''

created at 06-28-2021 views: 38


wrong code:

Item['job_minpayment']=str(round(int(re.split('\-', Item['job_minpayment'])[0])/12, 2)*10000)

What I got by crawling was a string like (number-number), and then I got the previous number through-division, and converted it to an integer, but something went wrong during the conversion process.

error message:

ValueError: invalid literal for int() with base 10: ''


I get ValueError because the int type cannot convert an empty string to an integer, indicating that I got an empty string before the conversion, or the string is empty or contains alphabetic characters before the int check as a parameter. It performs conversion, so an error occurred during the conversion process.


Now that we know where the error is, then we know how to solve this bug!
My method is:

Before the conversion, first output and print to see if I get a string like (number-number) that I requested. Before the int check, add a statement to check the content of the string:

except ValueError:
created at:06-28-2021
edited at: 06-28-2021: