相关疑难解决方法(0)

selenium如何在某些目标类中获取href的内容

我试图从网页检索数据有下面的html

       <div class="someclass">
       <p class="name"><a href="#/word/1/">helloworld</a></p>
       </div>
Run Code Online (Sandbox Code Playgroud)

我的目标是解析"#/ word/1 /"我所做的是

        target = self.driver.find_element_by_class_name('someclass')
        print target
        print target.text
        print target.get_attribute("css=a@href")
        print target.tag_name
Run Code Online (Sandbox Code Playgroud)

但输出是

 <selenium.webdriver.remote.webelement.WebElement object at 0x10bf16210>
 helloworld
 None
 div 
Run Code Online (Sandbox Code Playgroud)

我尝试了很多方法,似乎我无法在目标类中获得'a href'的内容.

我真的不想做的是获取页面的源代码,然后做一个字符串搜索,这似乎是愚蠢....

无论如何要得到它?

html css python selenium xpath

22
推荐指数
2
解决办法
4万
查看次数

标签 统计

css ×1

html ×1

python ×1

selenium ×1

xpath ×1