我有一系列網頁,我想要從所有不同的模式中刪除文本。我試圖編寫一個提取<br>
標籤後的文本的刮板,因爲該結構對所有頁面都是通用的。使用BeautifulSoup在<br>之後提取文本
的頁面遵循以下三個基本模式爲最佳,我可以告訴:
- http://www.p2016.org/ads1/bushad120215.html
- http://www.p2016.org/ads1/christiead100515.html
- http://www.p2016.org/ads1/patakiad041615.html
正如我現在,我用下面的刮迴路:
for br in soup.find_all('br'):
text = br.next_sibling
try:
print text.strip().replace("\t", " ").replace("\r", " ").replace('\n', ' ')
except AttributeError:
print('...')
儘管此腳本適用於某些頁面,但僅爲其他頁面獲取部分或全部文本。在過去的幾天裏,我一直在扯掉我的頭髮,所以任何幫助將不勝感激。
此外,我已經嘗試this technique,但無法使其適用於所有頁面。
沒有一個真正的「之間」爲
標籤,因爲沒有啓閉。我認爲你的意思是「之後」,對吧? –
對不起,是的。我將編輯該問題。 – StanO