带有bs4的正则表达式正在分割结果

2024-06-16 09:09:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我的正则表达式正在生成拆分结果,因此我必须为快速修复下标

代码

my_url = 'https://www.zoopla.co.uk/for-sale/property/b23/?page_size=100&q=B23&radius=0&results_sort=newest_listings&search_source=refine'

house_listings = page_soup.findAll("div", {"class":"listing-results-right clearfix"})

listings = house_listings[3] # item 3 for prototyping

house_type = re.findall('(?:(?!.for).)*', str(listings.h2.a.text))

print(house_type)
# `['4 bed detached house', '', 'for sale', '']`

修理

house_type = re.findall('(?:(?!.for).)*', str(listings.h2.a.text))[0]
print(house_type)
# 4 bed detached house

但除此之外,我需要一个新的正则表达式来更好地匹配

所需匹配项
从“bed”后面的单词开始(减去下面的空格),忽略“待售”部分。
e、 结果:detached houseterrace housesemi-detached houseflatmaisonette

来源https://www.zoopla.co.uk/for-sale/property/b23/?page_size=100&q=B23&radius=0&results_sort=newest_listings&search_source=refine


Tags: httpsforwwwtypepagepropertysaleresults