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'])
本文介绍了一种使用PhantomJS和Selenium进行网页抓取时遇到的问题:重定向失败导致页面源代码为空。文章提供了解决方案,即通过设置--ignore-ssl-errors=true参数来避免SSL握手失败。
2211

被折叠的 条评论
为什么被折叠?



