从表单中检索数据?
Retrieving data from a form?
我正在尝试使用 python 向网站输入数据,搜索它然后提取地址,但不确定此后该从何处继续。我的代码现在看起来像这样:
import mechanize
br = mechanize.Browser()
response = br.open("https://www.matsugov.us/myproperty")
for form in br.forms():
print "Form name:", form.name
print form
这给了我表单名称和表单。该表单在下拉列表下有多个字段,我需要 select 税号搜索并获取值“218N02W27C003”,然后应显示结果。从这个结果中,我们只需要获取包裹地址并显示输出。
因为您已经知道表单的 name,表单名称可以 selected using
for form in br.forms():
if form.attrs.get('name') == 'frmSearch':
br.form = form
break
要select下拉菜单中的选项,将选项的值作为列表传递
br.form['ddlType']=["taxid"]
总代码:
import mechanize
br = mechanize.Browser()
response = br.open("https://www.matsugov.us/myproperty")
for form in br.forms():
if form.attrs.get('name') == 'frmSearch':
br.form = form
break
br.form['ddlType']=["taxid"]
br['txtParm']="abcdef"
req=br.submit().read()
print req
参考 HTML 代码是这样的。
<select name="ddlType" id="ddlType">
<option value="owner">Owner Search</option>
<option value="buyer">Buyer Search</option>
<option value="address">Address Search</option>
<option value="subdivision">Subdivision Search</option>
<option value="subdivision2">Subdivision ID Search</option>
<option value="taxid">Tax ID Search</option>
<option value="parcel">Parcel ID Search</option>
</select>
我正在尝试使用 python 向网站输入数据,搜索它然后提取地址,但不确定此后该从何处继续。我的代码现在看起来像这样:
import mechanize
br = mechanize.Browser()
response = br.open("https://www.matsugov.us/myproperty")
for form in br.forms():
print "Form name:", form.name
print form
这给了我表单名称和表单。该表单在下拉列表下有多个字段,我需要 select 税号搜索并获取值“218N02W27C003”,然后应显示结果。从这个结果中,我们只需要获取包裹地址并显示输出。
因为您已经知道表单的 name,表单名称可以 selected using
for form in br.forms():
if form.attrs.get('name') == 'frmSearch':
br.form = form
break
要select下拉菜单中的选项,将选项的值作为列表传递
br.form['ddlType']=["taxid"]
总代码:
import mechanize
br = mechanize.Browser()
response = br.open("https://www.matsugov.us/myproperty")
for form in br.forms():
if form.attrs.get('name') == 'frmSearch':
br.form = form
break
br.form['ddlType']=["taxid"]
br['txtParm']="abcdef"
req=br.submit().read()
print req
参考 HTML 代码是这样的。
<select name="ddlType" id="ddlType">
<option value="owner">Owner Search</option>
<option value="buyer">Buyer Search</option>
<option value="address">Address Search</option>
<option value="subdivision">Subdivision Search</option>
<option value="subdivision2">Subdivision ID Search</option>
<option value="taxid">Tax ID Search</option>
<option value="parcel">Parcel ID Search</option>
</select>