안녕하세요.
I'm making a program to crawl with Python. It's a program that crawls the characteristics of a product.
rating = search_result.found("div", attrs={"class":"text-inline-block light average_number"}.get_text().strip()
I try to crawl a rating by searching for a product name on an evaluation site, but the problem is that there are some ratings and some don't. So, if you try to get a rating from the search results as shown above, get_text() will get an error if there is no rating. How can I configure it so that I can just pass if I don't have a rating?
python
It is possible through exception handling.
0/0
The above code outputs the ZeroDivisionError: division by zero
exception.
try:
0/0
except:
pass
If you make an exception as above, the exception caused by exception
will be processed pass
.
© 2024 OneMinuteCode. All rights reserved.