通过webdriver中的.title和.current_url获取title和url
1 from time import sleep 2 3 from selenium import webdriver 4 browser=webdriver.Firefox() 5 browser.get("http://www.zuzuche.com") 6 browser.find_element_by_link_text(u"门票玩乐").click() 7 sleep(3) 8 #获取当前的title 9 title=browser.title 10 print(title) 11 #对title做判断 12 if title==u"景点门票_特卖门票_门票优惠_打折门票_一日游_特价一日游_玩乐推荐_通票-租租车": 13 print("title ok") 14 else: 15 print("title no") 16 #获取当前的url 17 now_url=browser.current_url 18 print(now_url) 19 #对url做判断 20 if now_url=="http://poi.zuzuche.com/index-entrance-284ab515c664b25eb22fd29aaf3d553d.html?source=10000": 21 print("url ok") 22 else: 23 print("url on") 24 sleep(3) 25 26 browser.quit()