Different web site response with RoboBrowser

2019-05-11 19:04发布

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条回答
来,给爷笑一个
2楼-- · 2019-05-11 19:22

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.

查看更多
登录 后发表回答