Different web site response with RoboBrowser

旧街凉风 提交于 2019-12-10 09:37:36

问题


I'm trying to retrieve the HTML for a web site. When I view the page in Chrome I see a form with dates and rate options. But when I request the site with RoboBrowser I see a short HTML response which is completely different. What I am doing wrong?

My code:

from robobrowser import RoboBrowser
browser = RoboBrowser(parser='html.parser')

browser.open('http://www.marriott.com/reservation/availabilitySearch.mi?propertyCode=ATLRZ')

print(browser.parsed)

Result:

<!DOCTYPE doctype html>

<html>
<head><script src="/common/js/marriottCommon.js" type="text/javascript"> </script>
<meta charset="utf-8">
</meta></head>
<body>
<script>
        var xhttp = new XMLHttpRequest();
        xhttp.addEventListener("load", function(a,b,c){
          window.location.reload()
        });
        xhttp.open('GET', '/reservation/availabilitySearch.mi?istl_enable=true&istl_data', true);
        xhttp.send();
      </script>
</body>
</html>

回答1:


Try to imitate what a javascript-running browser would do. It looks like the site is reloading the page when it loads. That implies it might not let you access it unless you have the right cookies. The xhr request might be an additional check to prevent bots. So use browser.session to keep the cookies, send the xhr a request and then try to reload the page with your new cookies.



来源:https://stackoverflow.com/questions/41274956/different-web-site-response-with-robobrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!