У меня есть приведенный ниже html-код, где я анализирую рейтинги / текст и т. Д. Как я могу перебрать все классы div, содержащие "posting item" ниже div "wrap", используя lxml и tree?
С нижеприведеннымЯ получаю все выбранные элементы div одновременно:
forumposts = tree.xpath("//div[@class='wrap']//div[contains(@class, 'posting item')]")
# here i want to iterate through posting items
# so i should have 1 text/rating to process in the parse function
for post in forumposts:
parse(post)
HTML:
<div class="wrap">
<div class="posting item theme-international" data-postingid="1035091361">
<div class="thread">
<div class="js-ratings ratings">
<div class="js-ratings-counts ratings-counts" data-closable-
target="ratinglog-1-1035091361"
onclick="ForumLoader.toggleRatinglog(1035091361, 1)">
<span class="js-ratings-negative-count ratings-negative-
count">6</span>
<span class="js-ratings-positive-count ratings-positive-
count">7</span>
</div>
</div>
<div class="text">
<a href="xyz" rel="nofollow">
<strong/>
<span>Posting text 1 </span>
</a>
</div>
</div>
</div>
<div class="posting item theme-international" data-postingid="1035091361">
<div class="thread">
<div class="js-ratings ratings">
<div class="js-ratings-counts ratings-counts" data-closable-
target="ratinglog-1-1035091361"
onclick="ForumLoader.toggleRatinglog(1035091361,
1)">
<span class="js-ratings-negative-count ratings-negative-
count">1</span>
<span class="js-ratings-positive-count ratings-positive-
count">11</span>
</div>
</div>
<div class="text">
<a href="xyz" rel="nofollow">
<strong/>
<span>Posting text 2</span>
</a>
</div>
</div>
</div>
</div>