【发布时间】:2017-05-22 09:11:32
【问题描述】:
我正在尝试解析页面中 (type = text) 的所有输入标签:http://demo.testfire.net/feedback.aspx
正如您在上面的网址中看到的,有两种形式。
import bs4 as bs
import urllib.request
import requests
import webbrowser
import urllib.parse
url = "http://demo.testfire.net/feedback.aspx"
sauce = urllib.request.urlopen(url).read()
soup = bs.BeautifulSoup(sauce,"html.parser")
form = soup.find('form')
inputs = form.find('input', type='text').get('name')
print(inputs)
当我运行上面的代码时,我只得到第一个表单的 name 属性。即使我使用以下内容进行迭代:
for elements in inputs:
print(elements.get('name'))
我只得到第一种形式的名称属性。无论编号如何,如何解析任何页面的所有表单和所有输入。页面中的表单数量?
如果我使用 soup.find_all('form') 而不是 find(form) 我会收到错误消息。上面的代码有什么问题?
【问题讨论】:
标签: python beautifulsoup