Mad*_*ent 1 python selenium web-crawler scrape
我的代码:
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()
Run Code Online (Sandbox Code Playgroud)
我收到 TypeError: 'str' object is not callable on driver.current_url()。有关如何解决此问题的任何提示?
我将浏览此站点上的页面并抓取每个 URL。如果有另一种方法可以避免这种情况,请告诉我。
提前致谢。
仅使用driver.current_url而不是driver.current_url().
从文档:
一些属性是可调用的(或方法),而另一些是不可调用的(属性)。所有可调用的属性都以圆括号结尾。
所以,current_url是一个属性而不是一个方法,因此你不要调用它。
用法示例(Python 3):
my_url = driver.current_url
print(my_url)
Run Code Online (Sandbox Code Playgroud)