Python 通过PyQuery拆分刮取的数据

Python 通过PyQuery拆分刮取的数据,python,web-scraping,pyquery,Python,Web Scraping,Pyquery,我有以下情况: <div class="entry"> <p>one</p> <p>two<br />three<br />four</p> <p>five<br />six</p> </div> 这只会将其分成标记,完全忽略标记。我尝试了以下方法: list = [i.text() for i in s(table).find('p').find('br').i

我有以下情况:

<div class="entry">
<p>one</p>
<p>two<br />three<br />four</p>
<p>five<br />six</p>
</div>
这只会将其分成
标记,完全忽略

标记。我尝试了以下方法:

list = [i.text() for i in s(table).find('p').find('br').items()]
list = [i.text() for i in s(table).find('p').find('br').prevAll().items()]
list = [i.split('\n') for i in s(table).find('br').replaceWith('\n')]
这些都不起作用。此外,将
.replaceWith()
列为有效函数,但当我执行
test=s(table.find('br').replaceWith('anytext')
)时,它不会将其替换为任何内容,也不会出现任何错误,只是相同的项目列表,它们之间带有

标记。
.replaceWith()
是否对


进行了不同的处理

更复杂的例子

华盛顿东街122号
734-665-8767

Amadeus同时提供这两种定价选项

午餐2,15美元
选择:

蔬菜沙拉

午餐选择:
1戈拉贝克
3皮尔吉斯
3普莱斯基
基尔布萨
卡布斯塔沙拉
华沙沙拉
洋蓟沙拉
土豆沙拉

午餐15美元
三道菜餐
午餐主菜选择,配蔬菜沙拉和甜点

晚餐2,28美元

选择:
一杯汤
蔬菜沙拉

入口选择:
2土豆沙司
4土豆片
6皮尔吉斯
2戈拉布基
比戈斯
烤制克尔布萨
素食套餐
克拉科夫鸡
(一个胸脯)
罗非鱼
冷沙拉

晚餐28美元
四道菜餐
汤+蔬菜沙拉+晚餐主菜+甜点的选择

周日早午餐15美元
预期结果
[122 E.Washington St'、'734-665-8767'、'Amadeus提供两种定价选择'、'午餐2$15'、'Choose of:'、'Soup'、'Green沙拉'、'Choose of午餐菜:'、'1 Golabek'、'3 Piergies'、'3 Placeki'、'Kielbsa'、'Kapusta沙拉'、'Warsaw沙拉'、'洋蓟沙拉'、'Potato沙拉'、'午餐15美元'、'三道菜餐'、'Choose entré和d埃塞特','28美元晚餐2','Choice of soup','Cup of South','Green沙拉','Choice of entrée:','2土豆沙司','4土豆沙司','6 Piergis','2 Golabki','Bigos','Grilled Kielbsa','素食套餐','Krakow鸡肉(单胸)“,”罗非鱼“,”冷沙拉“,”晚餐28美元“,”四道菜餐“,”汤的选择+蔬菜沙拉+晚餐主菜+甜点“,”周日早午餐15美元“,”

pyquery的表现似乎不符合预期。使用
.contents()
的解决方案:


这对于我使用的简单示例有效,但是对于更复杂的场景,它不起作用。我已经编辑了我的OP。预期的结果是什么?
list = [i.text() for i in s(table).find('p').find('br').items()]
list = [i.text() for i in s(table).find('p').find('br').prevAll().items()]
list = [i.split('\n') for i in s(table).find('br').replaceWith('\n')]
<div class="entry">
<p>122 E. Washington St.<br />
734-665-8767</p>
<p>Amadeus is offering both pricing options.</p>
<p><strong>Lunch 2 for $15 </strong><br />
Choice of:<br />
<strong>Soup<br />
Green salad </strong></p>
<p>Choice of lunch dish:<br />
<strong>1 Golabek<br />
3 Piergies<br />
3 Placeki<br />
Kielbsa<br />
Kapusta salad<br />
Warsaw salad<br />
Artichoke salad<br />
Potato salad</strong></p>
<p><strong>Lunch $15</strong><br />
Three Course Meal<br />
Choice of lunch entrée with green salad and dessert</p>
<p><strong>Dinner 2 for $28</strong></p>
<p>Choice of:<br />
<strong>Cup of soup<br />
Green salad </strong></p>
<p>Choice of entrée:<br />
<strong>2 Potato Snitzel<br />
4 Potato Placeki<br />
6 Piergis<br />
2 Golabki<br />
Bigos<br />
Grilled Kielbsa<br />
Vegetarian combo<br />
Krakow Chicken </strong>(one breast)<br />
<strong>Tilapia<br />
Cold salad</strong></p>
<p><strong>Dinner $28</strong><br />
Four Course Meal<br />
Choice of soup + green salad + Dinner Entrée + Dessert </p>
<p><strong>Sunday Brunch $15</strong><br />
>>> import lxml

>>> [e for ptag in s('div.entry').find('p').items()
       for e in ptag.contents()
       if isinstance(e, lxml.etree._ElementStringResult)]
['one', 'two ', 'three', 'four', 'five', 'six']