2014-02-16 51 views

回答

8

如果使用find_by_* methods選擇元素,則這些元素返回的實例爲ElementLists。你選擇你感興趣的(最有可能的ElementAPI實例)的元素後,訪問屬性像一本字典:

the_element['href'] 
+0

太糟糕了'元素[「HREF」]'返回一個絕對URL(至少在Firefox中),而不是像HTML中的實際屬性,這可能是相對的。 –

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"])