【问题标题】:Get href value in Splinter?在 Splinter 中获取 href 值?
【发布时间】:2014-03-16 00:00:33
【问题描述】:

我想从 Splinter 中的 <a> 元素中获取 href 值。

有什么api方法吗?

【问题讨论】:

    标签: python href splinter


    【解决方案1】:
    #simplest possible working example demonstrating this in action
    import splinter
    b = splinter.Browser()
    b.visit("http://www.google.com")
    elems = b.find_by_tag("a")
    for e in elems:
        print(e["href"])
    

    【讨论】:

      【解决方案2】:

      如果您使用find_by_* methods 选择元素,则这些返回的实例为ElementLists。选择您感兴趣的元素(很可能是ElementAPI 实例)后,像字典一样访问该属性:

      the_element['href']
      

      【讨论】:

      • 太糟糕了 element['href'] 返回一个绝对 URL(至少在 Firefox 下),而不是实际属性,如 HTML 中的,可能是相对的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多