Issue
data = "Purchase requests: <span class="market_commodity_orders_header_promot">6008067</span><br>Start price: <span class="market_commodity_orders_header_promote">15,84 pуб.</span>"
sosoup = BeautifulSoup(data, "html.parser")
ququotes = sosoup.find_all('span', class_="market_commodity_orders_header_promote")
print(ququotes)
This code return me
[<span class="market_commodity_orders_header_promote">6007813</span>, <span class="market_commodity_orders_header_promote">15,82 pуб.</span>]
if i try
ququotes = sosoup.find('span', class_="market_commodity_orders_header_promote").get_text()
it's return me only first one number, how to get a second one?
Solution
There are a lot of approaches, select by index:
sosoup.find_all('span', class_="market_commodity_orders_header_promote")[1].text
Find first and than its next <span>
:
sosoup.find('span', class_="market_commodity_orders_header_promote").find_next('span').text
Or with css selectors
and next sibling (~):
sosoup.select_one('span.market_commodity_orders_header_promote ~ span').text
Answered By - HedgeHog
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.