如何在使用asp.net的网站上进行HTTP POST?

时间:2022-06-12 04:09:27

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.

我正在使用Python库请求,但我似乎无法登录到这个网站。网址是https://www.bet365affiliates.com/ui/pages/affiliates/,我一直在尝试将请求发送到https://www.bet365affiliates.com/Members/CMSitePages/SiteLogin.aspx?lng=1使用“ctl00 $ MasterHeaderPlaceHolder $ ctl00 $ passwordTextbox”,“ctl00 $ MasterHeaderPlaceHolder $ ctl00 $ userNameTextbox”等数据,但我似乎无法登录。

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

有经验的人可以查看页面的源代码并告诉我这里缺少什么?

2 个解决方案

#1


0  

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.

解决方案可能是这样的:请注意,你可以不用硒。如果你想没有它,首先你应该获得主联盟页面,并从响应数据中获取所有必需的信息(我通过xpaths收集)。我只是没有足够的时间在完全请求中写它。

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.

要从响应数据中收集信息,您可以使用XML树库。使用相同的XPATH方法,您可以轻松找到所有请求的信息。

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


0  

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

您是否检查过浏览器使用的http请求以使您登录?你应该复制它。

FB

#1


0  

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.

解决方案可能是这样的:请注意,你可以不用硒。如果你想没有它,首先你应该获得主联盟页面,并从响应数据中获取所有必需的信息(我通过xpaths收集)。我只是没有足够的时间在完全请求中写它。

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.

要从响应数据中收集信息,您可以使用XML树库。使用相同的XPATH方法,您可以轻松找到所有请求的信息。

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


0  

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

您是否检查过浏览器使用的http请求以使您登录?你应该复制它。

FB