Raphael Rafatpanah
Raphael Rafatpanah

Reputation: 19967

How to capture HTTP errors from python's webbrowser

I wrote a small python script to programatically open url's in chrome every six seconds.

#!/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)

I'm wondering if there is a way to also capture HTTP errors (i.e. 404) from Chrome back into python.

Upvotes: 1

Views: 299

Answers (1)

Nuncjo
Nuncjo

Reputation: 1340

I belive, it's not possible using webbrowser module. You should use something like selenium.

from seleniumrequests import Firefox

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

Upvotes: 1

Related Questions