如何在正則表達式中做'或'。我讀到我需要簡單地將各種表達式放入括號中,但是當我試圖在'Total:'或'Price for 1 night @'之後獲得任何輸出時,下面的findall不起作用。正則表達式findall邏輯或
p = re.findall(r'(Total: (.*))(Price for 1 night: (.*))',s)
給一些更多的上下文:
prices1=[]
soup = bs(content, 'lxml')
s=soup.prettify()
p = re.findall(r'(Total: (.*))|(Price for 1 night: (.*))',s)
for x in p:
if '£' in x:
num=int(x.replace('£',''))
prices1.append(num)
來源:
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
值的示例:
<strong class="price scarcity_color sr_gs_rackrate_price
anim_rack_rate
" title="Price for 1 night £69">
<b>
<span class="sr_gs_rackrate_total">Total: </span>
£69
</b>
</strong>
<td class="totalPrice" colspan="3">
<div data-component="track" data-hash="OLNYSRfCbdWGffSRe" data-stage="1" data-track="view"></div>
Total: £145
</td>
取而代之的是鏈接的,你可以有給我們的價值's' –
值是極長 – Nickpick
那麼也許只是有趣的部分? –