我正在尝试使用Python自动化报告流程 想法是登录页面然后获取URL: 您可以在屏幕截图中看到https://XXXXXXXXXXXXXXXXXXXXXX/#dashboard/1: 但如果你点击查看源,它就是Html代码(Na上面的东西):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>XXXXXXXXXXXXXXXX</title>
<link id="css-link" rel="stylesheet" href="css/app_108976.css" />
<link rel="apple-touch-icon" sizes="57x57" href="img/favicons/apple-touch- icon-57x57.png" />
<link rel="apple-touch-icon" sizes="60x60" href="img/favicons/apple-touch-icon-60x60.png" />
<link rel="icon" type="image/png" href="img/favicons/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="img/favicons/favicon-16x16.png" sizes="16x16" />
<link rel="manifest" href="img/favicons/manifest.json" />
<meta name="msapplication-TileColor" content="#2b5797" />
<meta name="theme-color" content="#ffffff" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<![endif]-->
<!--[if lte IE 8]>
<style type="text/css">
#browser-not-supported-container {
display: block;
text-align: left;
}
#login-panel-content {
display: none;
}
#browser-not-supported-link {
display: block;
padding-top: 10px;
}
#browser-not-supported-download-link {
text-decoration: underline;
}
</style>
<![endif]-->
</head>
<body>
<div id="feature-detection"></div>
<div id="main-page">
<noscript>
<div class="page login-page">
<div id="page-header" class="page-header">
<div class="page-header-logo-container">
<img class="page-header-logo" src="img/XXXXXXXXXXXXXXXXXXX.png" />
</div>
<!--
-->
<div class="user-menu"></div>
<div id="page-header-navbar" class="page-header-navbar"></div>
</div>
<div class="page-content">
<div id="login-container" class="login-container hidden">
<div class="login-container-top">
<div id="login-panel" class="login-panel">
<div id="login-panel-header" class="login-panel-header"></div>
<style type="text/css">
#login-panel-content {
display: none;
}
</style>
<div class="no-script-container">
<div class="no-script-content">
<div class="no-script-header">
JavaScript Disabled
</div> JavaScript is required to use this application.
</div>
</div>
</div>
</div>
</div>
</div>
<div class="page-footer"></div>
</div>
</noscript>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-6177009-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['www.XXXXXXXXXXXr.com'] );
ga('send', 'pageview');
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 973777747;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/973777747/?value=0&guid=ON&script=0" />
</div>
</noscript>
</div>
<script id="bootstrapper" src="js/main_108976.js"></script>
</body>
</html>
以下是我正在使用的Python代码:
import requests
url2 ="https://admin.XXXXXXXXXXXXX.net/#exec-reports"
payload +{"apiKey":"8770XXXXXX8t8","username":"XXXXXXXXXXXXX.net","password":"XXXXXXXXX","timestamp":"1449666522626"}
with requests.Session() as Req:
url ="https://admin.XXXXXXXXX.net/XXXXXXapi/v1/authenticatedSession"
Req.post(url, data=payload)
Response = Req.get(url2)
print (Response.headers)
print (Response.status_code)
print(Response.text)
这是输出: {'Accept-Ranges':'bytes','ETag':'W /“4290-1449645452000”','Last-Modified':'Wed,09 Dec 2015 07:17:32 GMT','Vary':' Accept-Encoding','Server':'XXXXXX','Transfer-Encoding':'chunked','Date':'Mon,14 Dec 2015 09:09:20 GMT','Content-Encoding':'gzip' ,'Content-Type':'text / html; charset = UTF-8','X-FRAME-OPTIONS':'SAMEORIGIN'} 200 以及上面发布的相同HTML。 问题是你有什么想法我如何能够检索我需要的数据?如果需要,我可以发布更多信息 非常感谢
答案 0 :(得分:0)
我发现了错误 我不得不使用:Req.post(Url3,data = Payload2,headers = reqHed) 并构建请求标头。 现在我得到400错误代码