可以使用以下正则表达式提取:

import re

a='https://www.booking.cn/hotel/cn/holidayinnxindu-chengdu.zh-cn.html?aid=1662037&ucfs=1&arphpl=1&dest_id=-1900349&dest_type=city&group_adults=2&req_adults=2&no_rooms=1&group_children=0&req_children=0&hpos=3&hapos=3&sr_order=popularity&nflt=class%3D4&srpvid=ca19373985640093&srepoch=1685173876&map_fdco=1&from=searchresults#hotelTmpl'

pattern = r'/hotel/cn/(.*?).zh-cn.html' result = re.findall(pattern, a) print(result[0])

输出结果为:

holidayinnxindu-chengdu

a=httpswwwbookingcnhotelcnholidayinnxindu-chengduzh-cnhtmlaid=1662037&ucfs=1&arphpl=1&dest_id=-1900349&dest_type=city&group_adults=2&req_adults=2&no_rooms=1&group_children=0&req_children=0&hpos=3&hapo

原文地址: https://www.cveoy.top/t/topic/fzaI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录