<table> <tbody id="tb-37327761306"> <tr class="sep-row"> <td colspan="5"></td> </tr> <tr class="tr-th"> <td colspan="5"> <span class="gap"></span> <span class="dealtime" title="2016-10-08 07:04:12" >2016-10-08 07:04:12</span > <input id="datasubmit-37327761306" value="2016-10-08 07:04:12" type="hidden" /> <span class="number" >订单号:<a name="orderIdLinks" id="idUrl37327761306" target="_blank" href="//details.jd.com/normal/item.action?orderid=37327761306&PassKey=8865F5A1FFB4DA5568429239E6A4CE80" clstag="click|keycount|orderinfo|order_num" >37327761306</a > </span> <div class="tr-operate"> <span class="order-shop"> <span class="shop-txt">京东</span> <a class="btn-im btn-im-jd" href="#none" title="联系客服" clstag="click|keycount|orderlist|ziyingchatim" ></a> </span> <a href="#none" clstag="click|keycount|orderlist|dingdanshanchu" class="order-del" _orderid="37327761306" _passkey="10413CA642EDECE687F5F7A4F38AFB6E" style="display: none" title="删除" ></a> </div> </td> </tr> </tbody> </table>
如果想要获取table里面的html信息该如何操作呢?
Selenium中有个page_source属性,但是那个是获取整个网页的html而不是元素的html。
driver.find_element_by_id('tb-37327761306').get_attribute('innerHTML')
- 通过 .get_attribute('outerHTML') 的方式可以获取某个元素的html信息;
- 通过 .get_attribute('innerHTML') 的方式可以获取某个元素的内部html信息;