【问题标题】:Why isn't my Python-based Selenium PhantomJS webcrawler reaching the web?为什么我的基于 Python 的 Selenium PhantomJS 网络爬虫无法访问网络?
【发布时间】:2013-08-06 15:01:50
【问题描述】:

我正试图让这个简单的代码到达 Internet。我在代理服务器后面,但我设置了 http_proxy、https_proxy 和 no_proxy 环境变量。

Python 代码:

from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get('http://www.google.com')
driver.page_source

输出:

u'<html><head><title> Web Authentication Redirect</title><meta http-equiv="Cache-control" content="no-cache"><meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Expires" content="-1"><meta http-equiv="refresh" content="1; URL=https://1.1.1.1/login.html?redirect=www.google.com/"></head><body>\n</body></html>'

关于如何解决这个问题的任何想法?

另外,我使用的是 Ubuntu 12.04 LTS。

【问题讨论】:

    标签: python proxy selenium-webdriver web-crawler phantomjs


    【解决方案1】:

    看起来您的网络上的某些东西会自行加载,然后立即将您重定向到您想去的地方。我认为您只需要在获取页面源之前遵循重定向即可。

    请参阅 Getting the final destination of a JavaScript redirect on a website 等待 selemium 遵循重定向。

    【讨论】:

      【解决方案2】:

      如果它是您登陆的页面,然后它会重定向您(也就是等待问题),那么您可以尝试wait.until(ExpectedConditions.titleIs("Google"))

      注意:这是 Java 代码,但转换起来应该不会太难。 waitWebDriverWait 的一个实例

      【讨论】:

        猜你喜欢
        • 2013-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多