簡體   English   中英

使用Mechanize(Python)填寫表單

[英]Using Mechanize (Python) to fill form

我想使用python mechanize填寫此頁面上的表單,然后記錄響應。 我該怎么辦? 當我使用以下代碼在此頁面上搜索表單時,它僅顯示搜索的表單。 如何找到其他表單的表單名稱以及名稱,性別等字段?

http://aapmaharashtra.org/join-us

碼:

import mechanize
br=mechanize.Browser()
br.open("http://aapmaharashtra.org/join-us")
for form in br.forms():
    print "Form name:", form.name
    print form

您需要的表單(帶有id="form1" )會動態加載 - 這就是您在select_forms()結果中看不到它的原因。

通過使用瀏覽器開發人員工具,您可能會發現該表單是從http://internal.aamaadmiparty.org/Directory/Format.aspx?master=blank鏈接加載的。

這是你應該從那開始:

import mechanize


br = mechanize.Browser()
br.open("http://internal.aamaadmiparty.org/Directory/Format.aspx?master=blank")
br.select_form(nr=0)

br.form['ctl00$MainContent$txtname'] = 'Test Name'
# fill out other fields

req = br.submit()

希望有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM