我想隔离网页的一部分,不幸的是它不包含在任何我可以拔出的内容中。BeautifulSoup,findAll('table')返回所有表格,但也返回它们之间的文本
我能得到的最接近的是获取整个网页的正文,然后尝试删除表格(这是我不想要的唯一部分)。
我使用的代码:
storyText = soup.body
toRemove = storyText.findAll('table')
for each in toRemove:
print each
目前最大的问题是,文档,删除行返回表和它们之间包含虽不在他们的文字。
所以我得到:
# Isolate body
findBody = soup.body
new = str(findBody)
# Section off the text from the tables before it.
sec = new.split('</table>')
# Select story area
newStory = sec[3]
# Section off the text from the tables after it.
newSec = newStory.split('<table')
# Select the story area, this the area that we want.
story = newSec[0]
我仍然在寻找一个答案,因为它似乎应该有一个更干净的方法:
<body>
<table>
table stuff
</table>
Text, not in tags </br> #This is what I want.
<table>
table stuff
</table
</body>
我已经做了以下在我的问题的工作去做这个。
因此,在您试图获取所有文本的示例页面上? – Serial
从它开始,是的。 – DasSnipez