Contact Python requests to find out how to resolve the get_text() error

Asked 2 years ago, Updated 2 years ago, 26 views

안녕하세요.

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

2022-09-20 19:02

1 Answers

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.


2022-09-20 19:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.