How to make HTTP POST on website that uses asp.net?

六月ゝ 毕业季﹏ 提交于 2020-01-17 06:10:33

问题


I'm using Python library requests for this, but I can't seem to be able to log in to this website. The url is https://www.bet365affiliates.com/ui/pages/affiliates/, and I've been trying post requests to https://www.bet365affiliates.com/Members/CMSitePages/SiteLogin.aspx?lng=1 with the data of "ctl00$MasterHeaderPlaceHolder$ctl00$passwordTextbox", "ctl00$MasterHeaderPlaceHolder$ctl00$userNameTextbox", etc, but I never seem to be able to get logged in.

Could someone more experienced check the page's source code and tell me what am I am missing here?


回答1:


The solution could be this: Please Take attention, you could do it without selenium. If you want to do without it, firstly you should get the main affiliate page, and from the response data you could fetch all the required information (which I gather by xpaths). I just didn't have enough time to write it in fully requests.

To gather the informations from response data you could use XML tree library. With the same XPATH method, you could easily find all the requested informations.

import requests
from selenium import webdriver

Password = 'YOURPASS'
Username = 'YOURUSERNAME'

browser = webdriver.Chrome(os.getcwd()+"/"+"Chromedriver.exe")
browser.get('https://www.bet365affiliates.com/ui/pages/affiliates/Affiliates.aspx')
VIEWSTATE=browser.find_element_by_xpath('//*[@id="__VIEWSTATE"]')
SESSIONID=browser.find_element_by_xpath('//*[@id="CMSessionId"]')
PREVPAG=browser.find_element_by_xpath('//*[@id="__PREVIOUSPAGE"]')
EVENTVALIDATION=browser.find_element_by_xpath('//* [@id="__EVENTVALIDATION"]')
cookies = browser.get_cookies()

session = requests.session()
for cookie in cookies:
    print cookie['name']
    print cookie['value']
    session.cookies.set(cookie['name'], cookie['value'])   

payload = {'ctl00_AjaxScriptManager_HiddenField':'',
           '__EVENTTARGET':'ctl00$MasterHeaderPlaceHolder$ctl00$goButton',
           '__EVENTARGUMENT':'',
           '__VIEWSTATE':VIEWSTATE,
           '__PREVIOUSPAGE':PREVPAG,
           '__EVENTVALIDATION':EVENTVALIDATION,
           'txtPassword':Username,
           'txtUserName':Password,
           'CMSessionId':SESSIONID,
           'returnURL':'/ui/pages/affiliates/Affiliates.aspx',
           'ctl00$MasterHeaderPlaceHolder$ctl00$userNameTextbox':Username,
           'ctl00$MasterHeaderPlaceHolder$ctl00$passwordTextbox':Password,
           'ctl00$MasterHeaderPlaceHolder$ctl00$tempPasswordTextbox':'Password'}


session.post('https://www.bet365affiliates.com/Members/CMSitePages/SiteLogin.aspx?lng=1',data=payload)



回答2:


Did you inspected the http request used by the browser to log you in? You should replicate it.

FB



来源:https://stackoverflow.com/questions/43137900/how-to-make-http-post-on-website-that-uses-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!