Practical solution to ValueError: invalid literal for int() with base 10 in Python

The crawler proxy IP is provided by the Sesame HTTP service provider.

Today , when I write a crawler program, I have to turn pages and do division and paging.

totalCount = '100'
totalPage = int (totalCount) / 20


ValueError: invalid literal for int() with base 10 The same error on the

Internet someone suggested to use round(float("1.0")), but it can't solve my problem, round(float("1.0")) is used to solve The floating point number is converted to an integer number,

and I do this because the original string is converted to an integer and then divided, although it may not report an error for a period of time, but it will prompt after a long time (actually it is a warning, but it will force you to terminate program), the correct solution is as follows:

remove the non-numeric characters in the string. Pro test available

totalCount = re.sub("\D", "", totalCount)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326468996&siteId=291194637