pythonseleniumweb-scrapingimdb

Is there a way to scrape the page url (or a part of it) located in the address bar using selenium in python?


I'm working on a huge dataset of movies and I'm trying to get the IMDb ID of each movie from the IMDB website. I'm using selenium in Python. I checked, but inside the movie page you can't find the IMDB code. It is contained into the link of the page, which is in the address bar and I don't know how to scrape it. Are there any methods of doing this?

This is an example of the page:

enter image description here

I need to get the underlined part of the url.

Does anyone know how to do it?


Solution

  • If you want to fetch the title of movie url you need to first fetch the current_url and then using python split() function you can get the second last string.

    currenturl=driver.current_url.split("/")[-2]
    print(currenturl)
    

    This will returned tt1877830