python - How to search for string with beautiful soup -


i'm trying parse below url. output of prices on site. first item £59.

i inspected element , found out html looks below. believe best way search class 'sr_gs_rackrate_total' or alternatively title starts "price for".

how can in beautiful soup?

<strong class="price scarcity_color sr_gs_rackrate_price  anim_rack_rate   " title="price 1 night £59"> <b> <span class="sr_gs_rackrate_total">total: </span> £59 </b> </strong> 

http://www.booking.com/searchresults.en-gb.html?label=gen173nr-17caeoggjcalhysdnibw5vcmvmafciaqgyas64aqtiaqtyaqhoaqh4aqs&sid=1a43e0952558ac0ad0061d5b6523a7bc&dcid=1&checkin_monthday=23;checkin_year_month=2016-1;checkout_monthday=24;checkout_year_month=2016-1;&city=-2601889&class_interval=1&csflt=%7b%7d&dtdisc=0&group_adults=7&group_children=0&highlighted_hotels=1192837&hlrd=0&hp_sbox=1&hyb_red=0&inac=0&label_click=undef&nflt=ht_id%3d201%3b&nha_red=0&no_rooms=1&redirected_from_city=0&redirected_from_landmark=0&redirected_from_region=0&review_score_group=empty&room1=a%2ca%2ca%2ca%2ca%2ca%2ca&sb_price_type=total&score_min=0&si=ai%2cco%2cci%2cre%2cdi&ss=london&ss_all=0&ssafas=1&ssb=empty&sshis=0&ssne=london&ssne_untouched=london&order=price_for_two

here 1 way that:

from bs4 import beautifulsoup soup = beautifulsoup(yourhtml) span = soup.find('span', {'class': 'sr_gs_rackrate_total'}) b = span.parent b.span.extract() b.text 

in case there more 1 span price in it, use

for span in soup.find_all('span', {'class': 'sr_gs_rackrate_total'}):   b = span.parent   b.span.extract()   print b.text 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -