mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-02-23 08:09:48 -05:00
Moving to python3
This commit is contained in:
parent
f90b4db690
commit
5900e90e7d
@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
from json import dumps, loads
|
||||
import os,sys,argparse, urllib2
|
||||
import os,sys,argparse, urllib.request, urllib.error, urllib.parse
|
||||
import websocket
|
||||
import thread
|
||||
import time
|
||||
import uuid
|
||||
import logging
|
||||
@ -17,20 +16,20 @@ class Umbra:
|
||||
self.launch_tab_socket.run_forever()
|
||||
|
||||
def get_websocket(self, on_open, url=None):
|
||||
debug_info = loads(urllib2.urlopen("http://localhost:%s/json" % self.chrome_debug_port).read())
|
||||
debug_info = loads(urllib.request.urlopen("http://localhost:%s/json" % self.chrome_debug_port).read())
|
||||
if url: #Polling for the data url we used to initialize the window
|
||||
while not filter(lambda x: x['url'] == url, debug_info):
|
||||
debug_info = loads(urllib2.urlopen("http://localhost:%s/json" % self.chrome_debug_port).read())
|
||||
while not [x for x in debug_info if x['url'] == url]:
|
||||
debug_info = loads(urllib.request.urlopen("http://localhost:%s/json" % self.chrome_debug_port).read())
|
||||
time.sleep(0.5)
|
||||
debug_info = filter(lambda x: x['url'] == url, debug_info)
|
||||
debug_info = [x for x in debug_info if x['url'] == url]
|
||||
return_socket = websocket.WebSocketApp(debug_info[0]['webSocketDebuggerUrl'], on_message = self.on_message)
|
||||
return_socket.on_open = on_open
|
||||
return return_socket
|
||||
|
||||
def on_message(self, ws, message):
|
||||
message = loads(message)
|
||||
if "method" in message.keys() and message["method"] == "Network.requestWillBeSent":
|
||||
print message
|
||||
if "method" in list(message.keys()) and message["method"] == "Network.requestWillBeSent":
|
||||
print(message)
|
||||
|
||||
def on_open(self, ws):
|
||||
self.fetch_url("http://archive.org")
|
||||
@ -69,14 +68,14 @@ class Chrome():
|
||||
start = time.time()
|
||||
open_debug_port = lambda conn: conn.laddr[1] == int(self.port)
|
||||
chrome_ps_wrapper = psutil.Process(self.chrome_process.pid)
|
||||
while time.time() - start < self.browser_wait and len(filter(open_debug_port, chrome_ps_wrapper.get_connections())) == 0:
|
||||
while time.time() - start < self.browser_wait and len(list(filter(open_debug_port, chrome_ps_wrapper.get_connections()))) == 0:
|
||||
time.sleep(1)
|
||||
if len(filter(open_debug_port, chrome_ps_wrapper.get_connections())) == 0:
|
||||
if len(list(filter(open_debug_port, chrome_ps_wrapper.get_connections()))) == 0:
|
||||
self.chrome_process.kill()
|
||||
raise Exception("Chrome failed to listen on the debug port in time!")
|
||||
|
||||
def __exit__(self, *args):
|
||||
print "Killing"
|
||||
print("Killing")
|
||||
self.chrome_process.kill()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user