我使用urllib登录网站,但我得到一个验证页面。我不明白我必须发送给服务器以克服障碍的答案。我想我知道我必须发送POST,但是通过发送所有内容我没有得到理想的结果。我应该发送一些特别的东西吗?东西?
如果有人可以帮助我,我将非常感激。谢谢。
这是我登录后得到的巨大答案...
<html>
<head>
<title>Working...</title> </head>
<body>
<form method="POST" name="hiddenform" action="https://site.domain.com:443/">
<input type="hidden" name="wa" value="wsignin1.0" />
<input type="hidden" name="wresult"
value="<t:RequestSecurityTokenResponse xmlns:t="
http://schemas.xmlsoap.org/ws/2005/02/trust">
< t:Lifetime><
wsu:Created xmlns:wsu="
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
>2020-04-04T19:44:03.524Z<
/wsu:Created>< wsu:Expires xmlns:wsu="
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
>2020-04-04T20:44:03.524Z<
/wsu:Expires></t:Lifetime>< wsp:AppliesTo xmlns:wsp="
http://schemas.xmlsoap.org/ws/2004/09/policy"
>< wsa:EndpointReference xmlns:wsa=" http://www.w3.org/2005/08/addressing"
>< wsa:Address>https://site.domain.com< /wsa:Address>< /wsa:EndpointReference>< /wsp:AppliesTo><
t:RequestedSecurityToken>< saml:Assertion MajorVersion="
1" MinorVersion=" 1" AssertionID="
_a0230c49-7fed-4469-bf9e-702b63ee7477" Issuer=" http://site2.domain.comadfs/services/trust"
IssueInstant=" 2020-04-04T19:44:03.524Z"
xmlns:saml=" urn:oasis:names:tc:SAML:1.0:assertion"
>< saml:Conditions NotBefore=" 2020-04-04T19:44:03.524Z" NotOnOrAfter="
2020-04-04T20:44:03.524Z"
>< saml:AudienceRestrictionCondition>< saml:Audience>https://site.domain.com< /saml:Audience><
/saml:AudienceRestrictionCondition>< /saml:Conditions><
saml:AttributeStatement>< saml:Subject><
saml:SubjectConfirmation><
saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer<
/saml:ConfirmationMethod>< /saml:SubjectConfirmation><
/saml:Subject>< saml:Attribute AttributeName="
implicitupn" AttributeNamespace="
http://schemas.xmlsoap.org/ws/2005/05/identity/claims"
>< saml:AttributeValue>[email protected]< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" accountthrottled"
AttributeNamespace="
http://schemas.microsoft.com/ws/2017/04/identity/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue b:type=" tn:boolean" xmlns:tn=" http://www.w3.org/2001/XMLSchema"
xmlns:b=" http://www.w3.org/2001/XMLSchema-instance"
>false< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute AttributeName=" familiarlocation"
AttributeNamespace="
http://schemas.microsoft.com/ws/2017/04/identity/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue b:type=" tn:boolean" xmlns:tn=" http://www.w3.org/2001/XMLSchema"
xmlns:b=" http://www.w3.org/2001/XMLSchema-instance"
>true< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute AttributeName=" authnmethodsproviders"
AttributeNamespace=" http://schemas.microsoft.com/claims"
>< saml:AttributeValue>FormsAuthentication< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" anchorclaimtype"
AttributeNamespace="
http://schemas.microsoft.com/ws/2014/01/identity/claims"
>< saml:AttributeValue>http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname<
/saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" upn" AttributeNamespace="
http://schemas.xmlsoap.org/ws/2005/05/identity/claims"
>< saml:AttributeValue>[email protected]< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" primarygroupsid"
AttributeNamespace="
http://schemas.microsoft.com/ws/2008/06/identity/claims"
>< saml:AttributeValue>S-1-5-21-4287071985-2918672672-1443967343-513<
/saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" primarysid" AttributeNamespace="
http://schemas.microsoft.com/ws/2008/06/identity/claims"
>< saml:AttributeValue>S-1-5-21-4287071985-2918672672-1443967343-48981<
/saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" name" AttributeNamespace="
http://schemas.xmlsoap.org/ws/2005/05/identity/claims"
>< saml:AttributeValue>Username1< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute AttributeName="
windowsaccountname" AttributeNamespace="
http://schemas.microsoft.com/ws/2008/06/identity/claims"
>
< saml:AttributeValue>Username1< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute AttributeName="
authnmethodsreferences" AttributeNamespace="
http://schemas.microsoft.com/claims"
>< saml:AttributeValue>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport<
/saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" groupsid" AttributeNamespace="
http://schemas.microsoft.com/ws/2008/06/identity/claims"
>< saml:AttributeValue>S-1-5-21-4287071985-2918672672-1443967343-513<
/saml:AttributeValue>< saml:AttributeValue>S-1-1-0<
/saml:AttributeValue>< saml:AttributeValue>S-1-5-32-545<
/saml:AttributeValue>< saml:AttributeValue>S-1-5-2<
/saml:AttributeValue>< saml:AttributeValue>S-1-5-11<
/saml:AttributeValue>< saml:AttributeValue>S-1-5-15<
/saml:AttributeValue><
saml:AttributeValue>S-1-5-21-4287071985-2918672672-1443967343-13989<
/saml:AttributeValue><
saml:AttributeValue>S-1-5-21-4287071985-2918672672-1443967343-38388<
/saml:AttributeValue><
saml:AttributeValue>S-1-5-21-4287071985-2918672672-1443967343-22934<
/saml:AttributeValue><
saml:AttributeValue>S-1-5-21-4287071985-2918672672-1443967343-11501<
/saml:AttributeValue>< saml:AttributeValue>S-1-18-2<
/saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" x-ms-client-user-agent"
AttributeNamespace="
http://schemas.microsoft.com/2012/01/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99
Safari/537.36< /saml:AttributeValue>< /saml:Attribute><
saml:Attribute AttributeName="
x-ms-endpoint-absolute-path" AttributeNamespace="
http://schemas.microsoft.com/2012/01/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>/adfs/ls/< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute AttributeName="
insidecorporatenetwork" AttributeNamespace="
http://schemas.microsoft.com/ws/2012/01"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue b:type=" tn:boolean" xmlns:tn=" http://www.w3.org/2001/XMLSchema"
xmlns:b=" http://www.w3.org/2001/XMLSchema-instance"
>false< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute AttributeName=" x-ms-proxy"
AttributeNamespace="
http://schemas.microsoft.com/2012/01/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>WAPDMZMR01< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute AttributeName="
client-request-id" AttributeNamespace="
http://schemas.microsoft.com/2012/01/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>605e2c74-b033-4ca8-81c4-0380010000ba< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" relyingpartytrustid"
AttributeNamespace="
http://schemas.microsoft.com/2012/01/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>https://site.domain.com< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" x-ms-client-ip"
AttributeNamespace="
http://schemas.microsoft.com/2012/01/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>10.244.3.252< /saml:AttributeValue>< /saml:Attribute>< saml:Attribute
AttributeName=" x-ms-forwarded-client-ip"
AttributeNamespace="
http://schemas.microsoft.com/2012/01/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>172.16.8.2< /saml:AttributeValue>< saml:AttributeValue>85.203.20.10< /saml:AttributeValue><
/saml:Attribute>< saml:Attribute AttributeName="
userip" AttributeNamespace="
http://schemas.microsoft.com/2014/09/requestcontext/claims"
a:OriginalIssuer=" CLIENT CONTEXT" xmlns:a="
http://schemas.xmlsoap.org/ws/2009/09/identity/claims"
>< saml:AttributeValue>85.203.20.10< /saml:AttributeValue>< /saml:Attribute><
/saml:AttributeStatement>< saml:AuthenticationStatement
AuthenticationMethod="
urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
AuthenticationInstant=" 2020-04-04T19:44:03.430Z"
>< saml:Subject>< saml:SubjectConfirmation>< saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer<
/saml:ConfirmationMethod>< /saml:SubjectConfirmation><
/saml:Subject>< /saml:AuthenticationStatement>< ds:Signature
xmlns:ds=" http://www.w3.org/2000/09/xmldsig#"
>< ds:SignedInfo>< ds:CanonicalizationMethod Algorithm=" http://www.w3.org/2001/10/xml-exc-c14n#" /><
ds:SignatureMethod Algorithm="
http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /><
ds:Reference URI="
#_a0230c49-7fed-4469-bf9e-702b63ee7477"
>< ds:Transforms>< ds:Transform Algorithm=" http://www.w3.org/2000/09/xmldsig#enveloped-signature" /><
ds:Transform Algorithm="
http://www.w3.org/2001/10/xml-exc-c14n#" /><
/ds:Transforms>< ds:DigestMethod Algorithm="
http://www.w3.org/2001/04/xmlenc#sha256" /><
ds:DigestValue>b1c+9bvSmPpFNvScSNJJpTbJ6LwIyo1RCvDVKY8QeuI=<
/ds:DigestValue>< /ds:Reference>< /ds:SignedInfo><
ds:SignatureValue>LA1dNOW7en/qQ5Z90WZTZ0Asb+BHubYP2MwDdGYh0AjsJMl+YIzC66h8hQfASOThETLlkwCkyOF1bvghWzOB6ZO/GgCgsGaEf8/Ed38zJVis2oFyAJz5Jj9XJ3tHRrpbFQdNEO8NHC8e8QgSiMep1j96rnT7BNiNqpkbCLsC/BB9B/c2RS6tYXRZhKVneXQtZAMjywgd+OH0IiUbbpiBbK2+/X16UhyHUTWzs6CJI7Pv9SQY6rv+PIdAp0iZugOmmufyEuHgHcqjMW9w64HBONSRIwqJ7/blEKGGto1Urp4vxzpMjr7428AZikr4rG/09ublQZ+WEjhwgEZlh/BDUw==<
/ds:SignatureValue>< KeyInfo xmlns="
http://www.w3.org/2000/09/xmldsig#"
>< X509Data>< X509Certificate>MIICzjCCAbagAwIBAgIQI9D9o/iPMbpLE+TnZuC+ITANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDExhBREZTIFNpZ25pbmcgLSBmcy5hdG0uaXQwHhcNMTkxMTE5MjMwOTQ5WhcNMjAxMTE4MjMwOTQ5WjAjMSEwHwYDVQQDExhBREZTIFNpZ25pbmcgLSBmcy5hdG0uaXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCkFFIK/Cn7t3E5VQ2jII/aH+2oEuK43MgtZp7hOcu431R3aUkXbevBVoOs5t6dOs2She9JL48RwcFeb6T1eiMT3HoYYfXERma4gy0SPQmGed1qtEApVo+Stxt4/V1B125tlpn9/xfpBasHyP/qCQIPSFxfgwRRYTN+cUtN9Wxjuw4m+dIySdk9c9POFvoC9vgB5tTSugWz2x02Cfi+hkDhWnPOaHFPE3V0vUZ3DGpJfiBGQizhnbZqaizjO6yQdWtkisoNX89GEmh6VTexSzlW9GCtDHLOqSjbkfEm8hU8H6kYsicot4ama/9RNcNHBx/kODPilIESuSm0zpyNEfw1AgMBAAEwDQYJKoZIhvcNAQELBQADggEBAD3LajP8S7I0fzl8rYqcmmhwsh6LvCVgigclt2YkFLD6MCJueacBs5NUcMmsiGa5JiY/FC405Iw9S2GhzBjNejDsyZAtplV/IShT6OOAp3GAWTkNDQoGdejbsExeRkFMCMAlLy2Nq1mnB6YwEMo4bHodG+ghQihxgSWQuFePKMuyrlZwvz07PDL56MCjiNrN+i1SHd1XCSwxpB2hY8LYN3EGqezKdyBbyVhAKgXTILPinxf1yciyoazLAg/5bMG33jTf31ijBDmsqbBD9FlDvUGp30uRXkbEUz/YXJC+p3acBmaUL5jGdyrO8dNj6ENYwmHEjlnLAAuBdDr9ly1czJM=<
/X509Certificate>< /X509Data>< /KeyInfo><
/ds:Signature>< /saml:Assertion><
/t:RequestedSecurityToken><
t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion<
/t:TokenType><
t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue<
/t:RequestType><
t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey<
/t:KeyType>< /t:RequestSecurityTokenResponse>" /><input
type="hidden" name="wctx" value="rm=0& id=passive& ru=%2f"
/><noscript><p>Script is disabled. Click Submit to continue.</p>
<input type="submit" value="Submit" /></noscript></form> <script
language="javascript">window.setTimeout('document.forms[0].submit()',
0); </script></body></html>
<input type="hidden" name="wa" value="wsignin1.0" />
<input type="hidden" name="wresult" value="(encoded XML)" />
<input type="hidden" name="wctx" value="rm=0& id=passive& ru=%2f"/>
并且网站在页面加载后立即使用脚本发布该表单:
window.setTimeout('document.forms[0].submit()', 0);
这意味着您需要执行相同的操作。
了解如何从响应HTML中检索表单字段及其值。
了解如何使用Python进行表单发布。当然可以使用urllib进行此操作,但是可以使用更高级的库,例如
requests
it's much easier。- [添加这三个表单字段及其值,并向
<form>
的action属性中的URL发送POST请求。- Web抓取库
scrapy
also offers a feature for doing this,这将使步骤#1和#2更容易。