2014-06-28 78 views
0

訪問了一個url後,我得到了許多表單。我想選擇其中bidder123456reason的表單爲seller,然後提交表單。使用機械化提交表單數據

這裏是形式列表

-----Start0---- 

<GET http://auctions.search.yahoo.co.jp/search application/x-www-form-urlencoded 
    <HiddenControl(auccat=) (readonly)> 
    <TextControl(p=)> 
    <SubmitControl(<None>=検 索) (readonly)> 
    <HiddenControl(tab_ex=commerce) (readonly)> 
    <HiddenControl(ei=UTF-8) (readonly)> 
    <HiddenControl(fr=auc_item) (readonly)>> 
-----End 0---- 
-----Start1---- 
<POST http://edit9.auctions.yahoo.co.jp/jp/config/amgr application/x-www-form-urlencoded 
    <HiddenControl(aID=k179213060) (readonly)> 
    <HiddenControl(bidder=123456) (readonly)> 
    <HiddenControl(action=rmwinner) (readonly)> 
    <HiddenControl(cc=jp) (readonly)> 
    <HiddenControl(hasRunnerUp=1) (readonly)> 
    <RadioControl(reason=[seller, winner])> 
    <SubmitControl(confirm=蜑企勁) (readonly)> 
    <HiddenControl(advance=on) (readonly)>> 
-----End 1---- 
-----Start2---- 
<POST http://edit9.auctions.yahoo.co.jp/jp/config/amgr application/x-www-form-urlencoded 
    <HiddenControl(aID=k179213060) (readonly)> 
    <HiddenControl(bidder=xxx) (readonly)> 
    <HiddenControl(action=rmwinner) (readonly)> 
    <HiddenControl(cc=jp) (readonly)> 
    <HiddenControl(hasRunnerUp=1) (readonly)> 
    <RadioControl(reason=[seller, winner])> 
    <SubmitControl(confirm=蜑企勁) (readonly)> 
    <HiddenControl(advance=on) (readonly)>> 
-----End 2---- 
-----Start3---- 
<POST http://edit9.auctions.yahoo.co.jp/jp/config/amgr application/x-www-form-urlencoded 
    <HiddenControl(aID=k179213060) (readonly)> 
    <HiddenControl(bidder=xxx) (readonly)> 
    <HiddenControl(action=rmwinner) (readonly)> 
    <HiddenControl(cc=jp) (readonly)> 
    <HiddenControl(hasRunnerUp=1) (readonly)> 
    <RadioControl(reason=[seller, winner])> 
    <SubmitControl(confirm=蜑企勁) (readonly)> 
    <HiddenControl(advance=on) (readonly)>> 
-----End 3---- 
-----Start4---- 
<p GET http://search.yahoo.co.jp/search application/x-www-form-urlencoded 
    <TextControl(p=)> 
    <SubmitButtonControl(<None>=) (readonly)> 
    <HiddenControl(ei=UTF-8) (readonly)> 
    <HiddenControl(fr=usf) (readonly)>> 
-----End 4---- 

我怎麼能這樣做?對不起,我沒有自己的代碼。 謝謝。

+0

[Submitting Forms with Mechanize(Python)](http://stackoverflow.com/questions/8570920/submitting-forms-with-mechanize-python) –

回答

0

.forms()返回的形式發電機,所以你需要檢查每一個用try-except塊。

for form in browser.forms(): 
    try: 
    if form.get_value('bidder') == '123456': 
     form['reason'] = ['seller'] 
     form.submit() 
     break 
    except ControlNotFoundError: 
    pass