Итак, у меня есть тег <tr>
с несколькими <td>
в качестве подстроки.
<tr>
<td align='center' class="row2">
<a href="javascript:who_posted(4713426);">10</a>
</td>
<td align="center" class="row2">
<a href='https://forum.net/index.php?;showuser=17311'>xxboxx</a>
</td>
<td align="center" class="row2">
<!--script type="text/javascript">
s = "236".replace(/,/g,'');
document.write(abbrNum(s,1));
</script-->
236
</td>
</tr>
это мой текущий код;у меня нет проблем с получением первых двух, но, пытаясь выбраться из сценария, я пробовал различные способы, предложенные другими похожими вопросами по stackoverflow;но я не был успешным.
def extractDataFromRow2(_url, 'td', 'row2', 'align' , 'center'):
try:
for container in _url.find_all('td', {'class': 'row2','align': 'center''}):
# get data from topic title in table cell
replies_numb = container.select_one(
'a[href^="javascript:]"').text
print('there are ' + replies_numb + ' replies')
topic_starter = container.next_sibling.text
print('the owner of this topic is ' + topic_starter)
for total_view in container.find('a', href=True, style=True):
#total_view = container.select_one(style="background-color:").text
#total_view = container.find(("td")["style"])
#total_view = container.next_sibling.find_next_sibling/next_sibling
#but they're not able to access the last one within <tr> tag
print(total_view )
if replies_numb and topic_starter is not None:
dict_replies = {'Replies' : replies_numb}
dict_topic_S = {'Topic_Starter' : topic_starter}
list_1.append(dict_replies)
list_2.append(dict_topic_S)
else:
print('no data')
except Exception as e:
print('Error.extractDataFromRow2:', e)
return None
Ссылка на страницу, с которой я пытаюсь получить данные.
, если есть более чистый подход к этому;Я более чем рад учиться на основе полученных отзывов.