我很难通过python3,beautifulsoup4抓到这个链接
http://www.radisson.com/lansing-hotel-mi-48933/lansing/hotel/dining
我只想得到这个部分。你知道吗
When you are in ...
Capitol City Grille
This downtown Lansing restaurant offers ...
Capitol City Grille Lounge
For a glass of wine or a ...
Room Service
If you prefer ...
我有这个密码
for rest in dining_page_soup.select("div.copy_left p strong"):
if rest.next_sibling is not None:
if rest.next_sibling.next_sibling is not None:
title = rest.text
desc = rest.next_sibling.next_sibling
print ("Title: "+title)
print (desc)
但它给了我TypeError: 'NoneType' object is not callable
在desc = rest.next_sibling.next_sibling
上,我甚至有一个if
语句来检查它是否是None
。你知道吗
如果您不介意使用xpath,这应该可以
这里的描述包含3个元素:“这个市中心…”,“为了一个杯子…”,“如果你喜欢…”。你知道吗
如果您还需要“When you are the mood…”,请替换为:
这是一个非常简单的解决方案
更新
根据问题的一个改进,这里是一个使用RE的解决方案。 必须为第一段“当你……”制定具体的解决办法,因为它不尊重其他段落的结构。你知道吗
输出
相关问题 更多 >
编程相关推荐