TypeError: 'str' object is not callable with driver.current_url() (Python 3.6)(Selenium)
TypeError: 'str' object is not callable with driver.current_url() (Python 3.6)(Selenium)
我的代码:
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=®ion=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()
我收到 TypeError: 'str' object is not callable on driver.current_url()。关于如何解决这个问题的任何提示?
我将 运行 浏览本网站的所有页面并抓取每个 URL。如果有另一种方法可以避免这种情况,请告诉我。
提前致谢。
仅使用 driver.current_url
而不是 driver.current_url()
。
来自docs:
Some attributes are callable (or methods) and others are non-callable
(properties). All the callable attributes are ending with round
brackets.
因此,current_url
是一个 属性 而不是一个方法,因此您不会 调用 它。
用法示例(Python 3):
my_url = driver.current_url
print(my_url)
尝试使用不带括号的 driver.current_url
。
消息错误告诉你 driver.current_url
是一个字符串,由于你不能调用字符串对象,所以 driver.current_url()
无法解释。
我的代码:
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=®ion=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()
我收到 TypeError: 'str' object is not callable on driver.current_url()。关于如何解决这个问题的任何提示?
我将 运行 浏览本网站的所有页面并抓取每个 URL。如果有另一种方法可以避免这种情况,请告诉我。
提前致谢。
仅使用 driver.current_url
而不是 driver.current_url()
。
来自docs:
Some attributes are callable (or methods) and others are non-callable (properties). All the callable attributes are ending with round brackets.
因此,current_url
是一个 属性 而不是一个方法,因此您不会 调用 它。
用法示例(Python 3):
my_url = driver.current_url
print(my_url)
尝试使用不带括号的 driver.current_url
。
消息错误告诉你 driver.current_url
是一个字符串,由于你不能调用字符串对象,所以 driver.current_url()
无法解释。