我有Python 2.7.3和bs。 版本是4.4.1Python BeautifulSoup從find_all返回錯誤輸入列表()
出於某種原因,這個代碼
from bs4 import BeautifulSoup # parsing
html = """
<html>
<head id="Head1"><title>Title</title></head>
<body>
<form id="form" action="login.php" method="post">
<input type="text" name="fname">
<input type="text" name="email" >
<input type="button" name="Submit" value="submit">
</form>
</body>
</html>
"""
html_proc = BeautifulSoup(html, 'html.parser')
for form in html_proc.find_all('form'):
for input in form.find_all('input'):
print "input:" + str(input)
返回輸入一個錯誤的列表:
input:<input name="fname" type="text">
<input name="email" type="text">
<input name="Submit" type="button" value="submit">
</input></input></input>
input:<input name="email" type="text">
<input name="Submit" type="button" value="submit">
</input></input>
input:<input name="Submit" type="button" value="submit">
</input>
它應該返回
input: <input name="fname" type="text">
input: <input type="text" name="email">
input: <input type="button" name="Submit" value="submit">
發生了什麼事?
謝謝。這工作。奇怪的是,我不得不用來結束我的輸入,因爲那不是標準的HTML代碼。 https://www.w3schools.com/tags/tag_input.asp,如果有人可以報告給適當的人,這將不勝感激。 – Arrow
@Arrow - 我可能會從https://bugs.launchpad.net/beautifulsoup/報告錯誤開始 – mgilson