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>
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
Post a Comment