2016-05-14 17 views
2

我想用python 3.4使用robobrowser刮一個html表單。我使用默認的HTML解析器:在不正確的網頁上刮一個表格

self._browser = RoboBrowser(history=True, parser="html.parser") 

它適用於正確的網頁,但現在我不得不解析寫錯誤的頁面。下面是HTML片段:

<form method="post" action="decide.php?act=submit_advance"> 
    <table class="td_advanced"> 
    <tr class="td_advance"> 
    <td colspan="4" class="td_advance"></strong><br></td> 
    <td colspan="3" class="td_left">Case sensitive:<br><br></td> 
    <td><input type="checkbox" name="case_sensitive" /><br><br></td> 
[...] 
</form> 

收盤strong標籤不正確。此錯誤會阻止解析器讀取此錯誤標記之後的所有輸入:

form = self._browser.get_form() 
print(form) 
>>> <RoboForm> 

有什麼建議嗎?

+0

如果它在robobrowser一個錯誤,你可以在GitHub上提交一個問題。 https://github.com/jmcarp/robobrowser –

+0

我認爲beautifulsoup應該處理標籤湯,所以這將是一個選擇考慮。 –

回答

0

我自己找到了解決方案。關於beautifulsoup的評論很有幫助,並以適當的方式進行了我的搜索。

解決方法是:使用另一個html解析器。我嘗試使用lxml,它適用於我。

self._browser = RoboBrowser(history=True, parser="lxml") 

由於PyPI將目前尚未享有LXML安裝與我的Python版本的工作,我下載了它從這裏:http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml