我正在尝试拆分以下标签:
<h3><a href="#AC Adapter" onclick="getProductsBasedOnCategoryID('Asus','AC Adapter','ET1611PUT','6941', this, 'E Series')">AC Adapter
</a></h3>
使用以下代码:
print "FETCHING CATEGORY"
atag = s.h3
for data in atag:
while getattr(atag, 'name', None) != 'h3':
atag = atag.nextSibling
atag.a
atag = literal_eval('(' + atag.nextSibling.replace(', this', '').split('(', 1)[1])
print atag
但是,我收到以下错误:
File "//CPSBS/RedirectedFolders/aysha/My Documents/asus_tables(edited) a tags.py", line 84, in <module>
atag = literal_eval('(' + atag.nextSibling.replace(', this', '').split('(', 1)[1])
IndexError: list index out of range
我猜我做错了什么?这个a
标签还有一个onclick
我想访问的属性,那么我如何将它输入到下面的代码中?
这是我解析数据的网址
http://www.asusparts.eu/partfinder/Asus/All In One/E 系列
[编辑]
导航树我正在尝试从中检索数据
<div id="accordion" class="ui-accordion ui-widget ui-helper-reset ui-accordion-icons" style="width: 760px;" role="tablist">
<h3 class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-top" role="tab" aria-expanded="true" aria-selected="true" tabindex="0">
<span class="ui-icon ui-icon-triangle-1-s"></span>
<a onclick="getProductsBasedOnCategoryID('Asus','AC Adapter','ET10B','6941', this, 'E Series')" href="#AC Adapter" tabindex="-1" loaded="Loaded">AC Adapter </a>
</h3>
<div id="6941" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active" role="tabpanel" style="display: block;">
<table class="productTableList">
<tbody>
</table>
<table class="productTableList">
<tbody>
<tr style="height:90px;background-color:#ebf4ff;">
<td class="ProduktLista" width="70px">
<td class="ProduktLista" width="315">
<a onclick="getProductInformationModal("Asus","14G110008340");">
<br>