我用BeautifulSoup和Python来刮一个网页。我有BS元素
a = soup.find('div', class_='section lot-details')
它返回一系列列表对象,如下所示。你知道吗
<li><strong>Location:</strong> WA - 222 Welshpool Road, Welshpool</li>
<li><strong>Deliver to:</strong> Pickup Only WA</li>
我想在每次str后返回文本
WA - 222 Welshpool Road, Welshpool
Pickup Only WA
我怎么才能从BS对象中得到这个呢?我不确定正则表达式,也不确定它如何与BeautifulSoup交互。你知道吗
你真的不需要正则表达式。如果列表中有
li
标记:这是假设在
li
中只有一个strong
元素,然后是文本。你知道吗或者,或者:
(?:</strong>)(.*)(?:</li>)
捕获字段\1
(.*)
将完成这项工作。你知道吗Python代码示例:
在这里检查https://regex101.com/r/fD0fZ9/1
相关问题 更多 >
编程相关推荐