User
User

Reputation: 24731

How to get the current page URL in the requests library?

I'm in a loop, navigating paged search results. The next button never disappears. I want to keep clicking it until the URL no longer changes. I imagine I will need a requests session? I want to do something like this:

new_url = soup.find("blahblah")['href']
if session.current_url == new_url:
    return

Upvotes: 7

Views: 10231

Answers (1)

User
User

Reputation: 24731

On the response object, there is a .url property that you can use to access the URL of the current page.

Upvotes: 11

Related Questions