Search code examples
pythonselenium-webdriverweb-scrapingweb-crawler

TypeError: 'str' object is not callable with driver.current_url() (Python 3.6)(Selenium)


My code:

https://pastebin.com/WKHZwAib

import selenium
from selenium import webdriver as web

url = 'https://www.wta.org/go-outside/hikes/hike_search? sort=&rating=0&mileage:float:list=0.0&mileage:float:list=25.0&title=&region=all&searchabletext=&filter=Search&subregion=all&b_start:int=0&show_incomplete=on&elevationgain:int:list=0&elevationgain:int:list=5000&highpoint='

driver = web.Chrome('D:/Development/Projects/Test/test/chromedriver')

driver.get(url)

driver.current_url()    

I am getting TypeError: 'str' object is not callable on driver.current_url(). Any tips on how I can resolve this?

I am going to be running through the pages on this site and grabbing each URL. If there is another way to do this that would avoid this, let me know.

Thanks in advance.


Solution

  • Use only driver.current_url instead of driver.current_url().

    From the docs:

    Some attributes are callable (or methods) and others are non-callable (properties). All the callable attributes are ending with round brackets.

    So, current_url is a property and not a method hence you don't call it.

    Usage Example (Python 3) :

    my_url = driver.current_url
    print(my_url)