href=httpswwwbookingcnhotelcnchengdu-qinyang-wuhou-temple-locals-apartment-00155970zh-cnhtmlsid=7c0a78f8c1db56ee42ab9578d1032f13&aid=1662037&ucfs=1&arphpl=1&checkin=2023-05-18&checkout=2023-05-19&dest
可以使用正则表达式提取该字符串:
import re
url = 'https://www.booking.cn/hotel/cn/chengdu-qinyang-wuhou-temple-locals-apartment-00155970.zh-cn.html?sid=7c0a78f8c1db56ee42ab9578d1032f13&aid=1662037&ucfs=1&arphpl=1&checkin=2023-05-18&checkout=2023-05-19&dest_id=-1900349&dest_type=city&group_adults=2&req_adults=2&no_rooms=1&group_children=0&req_children=0&hpos=25&hapos=25&sr_order=popularity&nflt=class%3D3&srpvid=5857127bd5ab00dc&srepoch=1683427064&all_sr_blocks=414124002_197391008_0_0_0&highlighted_blocks=414124002_197391008_0_0_0&matching_block_id=414124002_197391008_0_0_0&sr_pri_blocks=414124002_197391008_0_0_0__23117&from_sustainable_property_sr=1&from=searchresults#hotelTmpl'
pattern = r'/([\w-]+).zh-cn.html' match = re.search(pattern, url)
if match: print(match.group(1)) else: print('No match found.')
输出结果为:
chengdu-qinyang-wuhou-temple-locals-apartment-0015597
原文地址: https://www.cveoy.top/t/topic/euNE 著作权归作者所有。请勿转载和采集!