• R/O
  • HTTP
  • SSH
  • HTTPS

htmltree: 提交

メインリポジトリ


Commit MetaInfo

修订版5b7de89e976e9e5fbb978488f87c0f53249d9348 (tree)
时间2011-08-01 19:59:38
作者Hiromichi MATSUSHIMA <hirom@offi...>
CommiterHiromichi MATSUSHIMA

Log Message

fix get_elemnets_* to not find itsef

更改概述

差异

--- a/htmltree.py
+++ b/htmltree.py
@@ -202,7 +202,8 @@ class HTMLElement(list):
202202 # basic query functions
203203 def get_elements_by_name(self, name):
204204 buf = []
205- self._r_get_elements_by_name(name, buf)
205+ for i in self:
206+ i._r_get_elements_by_name(name, buf)
206207 return buf
207208
208209 def _r_get_elements_by_name(self, name, buf):
@@ -212,9 +213,9 @@ class HTMLElement(list):
212213 i._r_get_elements_by_name(name, buf)
213214
214215 def get_element_by_id(self, id):
215- if "id" in self.attrs and self.attrs["id"] == id:
216- return self
217216 for i in self:
217+ if "id" in i.attrs and i.attrs["id"] == id:
218+ return i
218219 e = i.get_element_by_id(id)
219220 if e != None:
220221 return e
@@ -223,7 +224,8 @@ class HTMLElement(list):
223224
224225 def get_elements_by_class(self, cls):
225226 buf = []
226- self._r_get_elements_by_class(cls, buf)
227+ for i in self:
228+ i._r_get_elements_by_class(cls, buf)
227229 return buf
228230
229231 def _r_get_elements_by_class(self, cls, buf):
@@ -276,6 +278,8 @@ class HTMLElement(list):
276278 results = [elem.get_element_by_id(pat[1:]),]
277279 elif pat[0] == ".":
278280 results = elem.get_elements_by_class(pat[1:])
281+ else:
282+ results = elem.get_elements_by_name(pat)
279283 return [x for x in results if x]
280284
281285 def select_1st(self, expr):
Show on old repository browser