无法弄清楚如何结合使用 Mechanize 和 Python 从 ASP.NET 页面上的下拉框中选择项目
我有一个 ASP.NET 页面(位于此处: http://www.kraftrecipes.com/Products/ ProductMain.aspx),有一个包含各种食品品牌的下拉框。我正在尝试在 Python 中使用 Mechanize,这样我就可以单击列表中的每个项目,转到产品列表页面,并最终使用 BeautifulSoup 来抓取产品信息。以下是一些 HTML:
<fieldset class="pulldownfieldset">
<label>...or use the pulldown menu below.</label>
<select name="ctl00$SPWebPartManager1$g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5$ctl01$ddlBrand"
id="ctl00_SPWebPartManager1_g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5_ctl01_ddlBrand"
onkeypress="return doSubmit(event, 'ctl00_SPWebPartManager1_g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5_ctl01_btnBrandGo');">
<option value="322">Arrowroot</option>
<option value="1">A.1. Steak Sauces and Marinades</option>
etc.
起初我只是尝试选择表单,但Python抱怨它不存在。
browser.select_form("ctl00$SPWebPartManager1$g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5$ctl01$ddlBrand")
当我这样做时:
browser.select_form(nr=0)
print browser.form
我得到了所有表单的列表,但是执行 browser.form.name
会产生“aspnetForm”,这让我相信 Mechanize 将页面上的所有内容视为一个大表单。如果这是真的,我怎样才能获得下拉框中的选择并提交它们?
如果您需要更多信息,请告诉我。
谢谢。
I have an ASP.NET page (located here: http://www.kraftrecipes.com/Products/ProductMain.aspx) that has a dropdown box of various food brands. I'm trying to use Mechanize in Python so I can click on each item in the list, go to the product list page, and eventually use BeautifulSoup to scrape product information. Here's some of the HTML:
<fieldset class="pulldownfieldset">
<label>...or use the pulldown menu below.</label>
<select name="ctl00$SPWebPartManager1$g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5$ctl01$ddlBrand"
id="ctl00_SPWebPartManager1_g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5_ctl01_ddlBrand"
onkeypress="return doSubmit(event, 'ctl00_SPWebPartManager1_g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5_ctl01_btnBrandGo');">
<option value="322">Arrowroot</option>
<option value="1">A.1. Steak Sauces and Marinades</option>
etc.
At first I just tried selecting the form, but Python complained that it didn't exist.
browser.select_form("ctl00$SPWebPartManager1$g_9bdf5859_9c73_4144_8b6a_9a3b3df417d5$ctl01$ddlBrand")
When I do this:
browser.select_form(nr=0)
print browser.form
I get a list of all of the forms, but doing browser.form.name
yields "aspnetForm", which leads me to believe that Mechanize sees everything on the page as one big form. If this is true, how can I get at the selections in the dropdown box and submit them?
Let me know if you need more information.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
页面上只有一个表格。你想要的是控制。
尝试:
There is only one form on the page. What you want is controls.
Try: