my python3 code:
import requests
url = sys.argv[1]
r = requests.get(url, stream=True)
chunk_size = 20000
with open('metadata.pdf', 'wb') as fd:
for chunk in r.iter_content(chunk_size):
fd.write(chunk)
It saves the content in metadat.pdf but that is not the real content of pdf, it is this html page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<!-- $HTMLid: index.html /main/6 11-Jun-2004.13:54:09 $ -->
<head>
<title>Allied Waste</title>
<script language="JavaScript">
<!--
if (top != self) {
top.location = self.location;
}
function doRedirect() {
document.login.submit();
}
function init () {
var initChar = /^\?/;
var list = top.location.search.replace(initChar,"");
var parms = list.split('&');
for ( ct=0; ct < parms.length; ct++ ) {
vals = parms[ct].split('=');
switch ( vals[0] ) {
case "unitCode":
document.login.unitCode.value = unescape(vals[1]);
if ( document.login.unitCode.value == 'undefined' || document.login.unitCode.value == '' )
document.login.unitCode.value = "ALW";
break;
default:
document.login.unitCode.value = "ALW";
break;
}
}
document.login.submit();
}
//-->
</script>
</head>
<body onload="init()">
<form name="login" action="inetSrv" method="post">
<input type="hidden" name="type" value="SignonService"/>
<input type="hidden" name="action" value="SignonPrompt"/>
<input type="hidden" name="client" value="701122300"/>
<input type="hidden" name="unitCode" value=""/>
</form>
</body>
</html>
Any help, how I can save the real content of the file, not this html? It should be the real pdf, and when i download it it is jsut this html page
UPDATE:
aNSWER FROM THE SERVER when I use python sessions:
b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n\n \n<head><title></title>\n \n<LINK REL="StyleSheet" HREF="styles/mainStyle.css">\n</head>\n\n<body>\n<div style="float: left; border: 1px solid black; background-color: #FFFFFF; padding: 5px">\n\t<div class="TitleFont">Operation failed</div>\n\t<div class="TitleFont">Reason</div>\n\t<div>\n\t<div class="custom-message-box">\n\t\t\t\t<div class="ErrorFont" ALIGN="left" >A server error has occurred.</div>\n\t\t\t\t<div class="ErrorFont" ALIGN="left" >Error reference id: DLY-00716</div>\n\t\t\t\t<div class="ErrorFont" ALIGN="left" >Time: Wed Jul 15 05:33:12 CDT 2020</div>\n\t</div>\n\t</div>\n\t<div style="width: 600px">\n\t\t<p class="form-style-text">\n\t\tIf contacting customer support, please quote the above error reference id. You may be able to press the browser Back button to return to the previous screen. Otherwise you may need to login again. We apologize for the inconvenience.\n\t\t</p>\n\t</div>\n</div>\n\n</body>\n</html>\n\n'