Skip to content
Advertisement

Python: href tag TypeError

I tried running my web scraping code. Sometime it works fine, but sometime it will give me Traceback Type Error code. I am wondering what is causing the error code?

Here is the error message:

JavaScript
JavaScript

Advertisement

Answer

You have to check if nextLink is not None before you try to get ['href']

JavaScript

and when nextLink is None then it can return None and you have to check it in main loop

JavaScript

Full working code

JavaScript

Result:

JavaScript

PEP 8 — Style Guide for Python Code

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement