Python Selenium???????????????????????
???????????? ???????[ 2014/6/17 13:59:21 ] ????????Selenium ????????????
????????????????????????棬???????python???????????????????????е?????????????????????????????????????????????????????????????檔
?????????????????????3??
????1. ???????????????е???????????????????
????2. ??????????????“????”???????
????3. ?????????????????????????
???????????????????????????????????selenium?????????find_elements_by_tag_name????????????????????webdriver???????
????driver.find_elements_by_tag_name("a")
???????????????????a?????
???????????????е?a??????е???????????????????????????е?a??????????????涼????????п??????????????????????????????????????????????????????????????????????????
???????????
???????selenium.webdriver.remote.webelement.WebElement????get_attribute??????
???????get_attribute?????a?????????????????ж?????????????????е????
????get_attribute("href") ???a???????????????URL????URL?????ж????????????????????檔????????????????????????????????????????????·????????????????????????????????????????????????????“http”?????url??
????get_attribute("target")???target????"_blank"??????????ж????????????????????
??????????????????η???????????
????selenium webdriver ????back????????????????????driver.back()
?????????????????????????????????????????в???????????????????for loop??
????for i in range(0?? len(driver.find_elements_by_tag_name("a"))):
??????python?У???????????i??range(0?? x)????????????1?????????????0??(x-1)?????С????磺range(0??5)????[0?? 1?? 2?? 3?? 4]?????????????range??????????????range?????????????????????磺range(0??5??2)???????2??????????[0??2??4]??????С?
????????????????????????C#??foreach???????
????for targetLink in driver.find_elements_by_tag_name("a")??
????????????????????????е?a????????е?????????
?????????????????????????????????????????????
links = driver.find_elements_by_tag_name("a")
for link in links:
if not "_blank" in link.get_attribute("target") and ("google" in link.et_attribute("href") or not "http" in link.get_attribute("href")):
link.click()
driver.back()
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11