Python - Requests/RoboBrowser - ASPX POST JavaScript

后端 未结 1 1023
一生所求
一生所求 2021-01-06 18:12

I am porting a bash script that uses curl and POSTs the payloads in the code to the URL\'s and works. The basic issue is that, with robobrowser, I\'m running into trouble po

相关标签:
1条回答
  • 2021-01-06 18:43

    Solved

    After much googling, re-posting for help on reddit and then randomly stumbling this RoboBrowser issue that showed me how to properly use the 'fields.add_field()' method; the problem is solved.

    e.g.

    b_e_arg = robobrowser.forms.fields.Input('\<input name="__EVENTARGUMENT" value="" \/\>')
    
    b_e_target = robobrowser.forms.fields.Input('\<input name="__EVENTTARGET" value="PhoneListsControl$MasterDataControl$masterList$_ctl0$SelectButton" \/\>')
    
    In [30]: form_find_b.add_field(b_e_target)
    In [31]: form_find_b.add_field(b_e_arg)
    

    Once the form was updated with these values, the form submit to "PhoneLists.aspx" works as expected.

    In [33]: m.submit_form(form_find_b)
    
    In [34]: m.url
    Out[34]: u'http://example/PhoneLists.aspx'
    
    In [35]: m.parsed.findAll('div', id='PhoneListsControl_phoneListMembersText')
    Out[35]: [<div class="displayText" id="PhoneListsControl_phoneListMembersText">  Work  </div>]
    
    In [36]: m.parsed.findAll('input', id='PhoneListsControl_phoneListDetail__ctl2_number')
    Out[36]: [<input id="PhoneListsControl_phoneListDetail__ctl2_number" maxlength="50" name="PhoneListsControl:phoneListDetail:_ctl2:number" onkeyup="enableApplyButton('PhoneListsControl_')" type="text" value="95551234567"/>]
    

    I hope anyone else that has to scrape ASPX sites finds this useful. Happy hacking to all!

    0 讨论(0)
提交回复
热议问题