【问题标题】:How to capture HTTP errors from python's webbrowser如何从 python 的网络浏览器捕获 HTTP 错误
【发布时间】:2016-02-06 20:10:30
【问题描述】:

我编写了一个小 Python 脚本,每六秒以编程方式在 chrome 中打开 url。

#!/usr/bin/env python

import webbrowser
import time

f = open("data.txt", "r")
urls = f.readlines()

safari = webbrowser.get('open -a /Applications/Google\ Chrome.app %s')

for url in urls:
    safari.open(url.replace("\n", ""))
    print url
    time.sleep(6)

我想知道是否有办法将 HTTP 错误(即 404)从 Chrome 捕获回 python。

【问题讨论】:

    标签: python macos google-chrome python-webbrowser


    【解决方案1】:

    我相信,使用 webbrowser 模块是不可能的。你应该使用像 selenium 这样的东西。

    from seleniumrequests import Firefox
    
    webdriver = Firefox()
    response = webdriver.request('GET', 'https://www.google.com/')
    print(response)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 2014-09-23
      • 2013-01-06
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 2014-08-10
      相关资源
      最近更新 更多