[PhantomJS] Https Redirect Problem with PhantomJS + Selenium

来源:互联网 发布:心理咨询知乎 编辑:程序博客网 时间:2024/06/09 19:12

A few days ago, I was writing a python script with PhantomJS and Selenium, but the redirection doesn’t work properly.

Problem

For example,

driver.get("https://redirect-to-login.example.com")driver.page_source

The page_source is empty.

Solution

I found this article(https://stackoverflow.com/questions/29358269/handling-redirection-w-phantomjs-selenium).

The reason is that when doing https redirect, it is possible SSL handshake will fail.
So we need to add --ignore-ssl-errors=true when initializing the driver

driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'])
原创粉丝点击