我正在使用python向php脚本发送一个get请求:
import requests
session = requests.Session()
response = session.get("someurl/somemore/smth.php")
我注意到返回的HTML与我预期的不一样(我在浏览器中看到的HTML)所以我查看了Firefox Developer Tools并写下了我在标题中找到的相同参数:
headers = {"A awful lot of stuff":"stuff",...}
但我仍然没有得到预期的HTML。有一个“Cookie” - 参数是特定于会话的(PHPSESSID)所以我修改了这个参数如下:
Cookie: "PHPSESSID="+session.cookies.get_dict()["PHPSESSID"]
这似乎工作正常,但我仍然得到一个不同的HTML。 这是为什么?浏览器的解释还有什么其他差异,我如何在python中模拟它们(使用请求,而不是selenium) 谢谢大家
附录: 我用脚本收到的代码:
<script language="JavaScript">
top.location.href = "logout.php";
</script>
原始的,未解释的HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html id="MapFrameID1">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Map</title>
<style type="text/css">
p,ul,ol,td,span,
layer,table,body { font-family: Arial, helvetica, sans-serif; font-size: 12px; color: #222222; }
p { margin: 0px; padding: 0px; }
a:link { color:#CC3300; text-decoration:none; font-weight:bold; }
a:visited { color:#CC3300; text-decoration:none; font-weight:bold; }
a:active { color:#FF3300; text-decoration:hover; font-weight:bold; }
a:hover { color:#FF3300; text-decoration:underline; font-weight:bold; }
h1 { font-size:12px; font-weight:bold; margin-bottom: 0px;}
.medium { font-size:11px; }
.small { font-size:10px; }
.framemapbg { margin: 10px; margin-top: 3px; }
p.positiontext { background-color: #BBBBBB; border: 1px solid #555555; color: #000000; font-size: 10px; margin-left: 0px; margin-right: 0px; margin-bottom: 3px; padding-left: 0px; padding-right: 0px; width: 100%; }
a.nocango:hover:after { content: ""; position: absolute; bottom: .25em; right: .25em; background: white; border: 0 solid red; border-width: .28em .12em; width: .56em; height: .24em; cursor: default; }
a:focus { outline:0; -moz-outline:0; }
</style>
<script type="text/javascript">
function stopErrors() {
return true;
}
window.onerror = stopErrors;
var target="test";
var timer;
function countdown()
{
millisekunden = ende - new Date().getTime();
text = Math.ceil(millisekunden / 1000);
x = document.getElementById(target);
if(millisekunden > 0)
text2 = 'Du kannst in ' + (text/60>=1?Math.floor(text/60)+' Minuten und ':'')+(text%60) + ' Sekunden weiterreisen';
else
text2 = '';
x.innerHTML = text2;
if (millisekunden<=0)
window.clearInterval(timer);
}
function refreshtravel(newtravel)
{
if(newtravel > 1)
{
var oldwielang = ende - new Date().getTime();
ende = newtravel * 1000 + new Date().getTime();
if(oldwielang<=0)
{
setTimeout(function() {
countdown();
timer = window.setInterval("countdown()", 1000);
}, ende % 1000);
countdown();
}
}
else
{
if(ende - new Date().getTime() > 1000)
ende = 0;
}
}
function Move(dirx, diry)
{
if(ende - new Date().getTime() <= 1000)
{
location.href = 'map.php?walkX=' + dirx + '&walkY=' + diry + '&intwalkid=574928190';
}
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="framemapbg">
<script language="JavaScript">
var mainForm = parent.frames.mainFrame.formular, itemFrame = parent.frames.itemFrame;
if (parent.frames.reloadChatFrame.active_websocket == false)
{
parent.frames.chattextFrame.location.href = 'chattext.php';
if(mainForm && (mainForm.block_reload.value != 'true' || (mainForm.block_reload_pos && mainForm.block_reload_pos.value != '104|100')))
{
parent.frames.mainFrame.location.href = 'main.php';
}
}
if(itemFrame && itemFrame.formular && itemFrame.formular.block_reload.value != 'true')
{
parent.frames.itemFrame.location.href = 'item.php';
}
var tele = parent.frames.chatformFrame.document.chatform.tele;
var group = parent.frames.chatformFrame.document.chatform.group;
if (tele)
{
tele.style.display = 'none';
tele.removeAttribute('accesskey');
}
if (group)
{
group.style.display = 'none';
group.removeAttribute('accesskey');
}
</script>
<div align="center">
<p class="positiontext"><a href="map.php?&reload=1"><img src="../images/relmap.gif" align="top" border=0></a> Position X: 104 Y: 100</p>
</div>
<style type="text/css">
a.nocango { background: #transparent; height: 100%; width: 100%; border-width: 0; display: block; }
.mapstate { -webkit-touch-callout: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
.maptable, .maptable * { font-family: Verdana, sans-serif; font-size: 17px; font-weight: bold; }
</style>
<table class="maptable" width="250" height="250" border="0" align="center" cellpadding="0" cellspacing="0" data-mapsize="5"><tr><td id="mapx102y98" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx103y98" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx104y98" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx105y98" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx106y98" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td></tr><tr><td id="mapx102y99" style="background-image:url(../images/map/wasserfall.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: default;"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc>Nordwesten</desc></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0" alt="Nordwesten"><![endif]--></a></td><td id="mapx103y99" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(-1, -1);" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx104y99" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(0, -1);" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx105y99" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(1, -1);" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx106y99" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td></tr><tr><td id="mapx102y100" style="background-image:url(../images/map/wiese2.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: default;"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc>Westen</desc></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0" alt="Westen"><![endif]--></a></td><td id="mapx103y100" style="background-image:url(../images/map/akademie2.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(-1, 0);" ><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc>Westen</desc></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0" alt="Westen"><![endif]--></a></td><td id="mapx104y100" style="background-image:url(../images/map/wies7.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(0, 0);" ><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc></desc><path class="user" d="M 17 21 L 21 17 L 25 21 L 29 17 L 33 21 L 29 25 L 33 29 L 29 33 L 25 29 L 21 33 L 17 29 L 21 25 Z" stroke="red" fill="white" /></svg><!--<![endif]--><!--[if IE]><img src="../images/map/user.gif" width="50" height="50" border="0" alt=""><![endif]--></a></td><td id="mapx105y100" style="background-image:url(../images/map/wies8.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(1, 0);" ><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc>Osten</desc></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0" alt="Osten"><![endif]--></a></td><td id="mapx106y100" style="background-image:url(../images/map/wies11.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: default;"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc>Osten</desc></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0" alt="Osten"><![endif]--></a></td></tr><tr><td id="mapx102y101" style="background-image:url(../images/map/wiese3.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: default;"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc>Südwesten</desc></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0" alt="Südwesten"><![endif]--></a></td><td id="mapx103y101" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(-1, 1);" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx104y101" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(0, 1);" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx105y101" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none; cursor: pointer;" onClick="javascript:Move(1, 1);" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx106y101" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td></tr><tr><td id="mapx102y102" style="background-image:url(../images/map/forest3.jpg); background-size: 50px 50px; position: relative;" class="maptd"><a style="text-decoration: none; cursor: default;"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"><desc>Südwesten</desc></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0" alt="Südwesten"><![endif]--></a></td><td id="mapx103y102" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx104y102" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx105y102" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td><td id="mapx106y102" style="background-image:url(../images/map/std.jpg); background-size: 50px 50px; position: relative;;" class="stdjpg"><a style="text-decoration: none;" class="nocango"><!--[if !IE]>--><svg width='50' height='50' class="mapstate"></svg><!--<![endif]--><!--[if IE]><img src="../images/map/zahl0.gif" width="50" height="50" border="0"><![endif]--></a></td></tr></table>
<div id="test" align="center" class="small"></div>
<script type="text/javascript">
var ende = new Date().getTime() + -3240600;
setTimeout(function() {
countdown();
timer = window.setInterval("countdown()", 1000);
}, ende % 1000);
countdown();
</script>
<script language="JavaScript">
document.body.background = '../images/itembg.jpg';
</script>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="1" onClick="parent.itemFrame.document.getElementById('accessfast1').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="2" onClick="parent.itemFrame.document.getElementById('accessfast2').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="3" onClick="parent.itemFrame.document.getElementById('accessfast3').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="4" onClick="parent.itemFrame.document.getElementById('accessfast4').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="5" onClick="parent.itemFrame.document.getElementById('accessfast5').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="6" onClick="parent.itemFrame.document.getElementById('accessfast6').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="7" onClick="parent.itemFrame.document.getElementById('accessfast7').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="8" onClick="parent.itemFrame.document.getElementById('accessfast8').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="9" onClick="parent.itemFrame.document.getElementById('accessfast9').click(); parent.itemFrame.focus();"></div>
<div style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; overflow: hidden;"><input type="button" accesskey="i" onClick="var search = parent.itemFrame.document.getElementById('searcht'); if (search) { search.value = ''; search.focus(); parent.document.getElementById('searchsave').value = ''; } else { parent.itemFrame.location.href = 'item.php?action=openinv'; }"></div>
</body>
</html>