python selenium2 定位一組元素find_elements實例


 

打開hao123首頁,需要定位以上區域中的所有鏈接,他們有相同的父元素<ul class="js_bd site-bd site-hd0">,所有鏈接處在li>a標簽下

如下操作

#coding=utf-8
from selenium import webdriver
import time

base_url = "http://www.hao123.com"
driver = webdriver.Firefox()
driver.get(base_url)
s = driver.find_elements_by_css_selector("ul.js_bd.site-bd.site-hd0>li>a")
for i in s:
    print i.get_attribute("href")

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM