मैं इसे स्वयं उपयोग करता हूं: (मैंने लिखा है क्योंकि यह केवल व्यक्तिगत उपयोग के लिए था)। बहुत साफ होने के साथ आप जो चाहते हैं उसे पाने में सक्षम हो सकते हैं। https://developers.google.com/chrome-developer-tools/docs/remote-debugging
import urllib2
import urllib
import os
import subprocess
import json
from websocket import create_connection
def refresh_page(url):
data = json.load(urllib2.urlopen('http://localhost:9222/json'))
found_page = False
for page in data:
if page['url'].lower() == url.lower():
found_page = True
websocketURL = page['webSocketDebuggerUrl']
ws = create_connection(websocketURL)
obj = { "id": 0,
"method": "Page.reload",
"params":
{
"ignoreCache": True,
"scriptToEvaluateOnLoad": ""
}
}
dev_request = json.dumps(obj)
ws.send(dev_request)
result = ws.recv()
ws.close()
if not found_page:
raise Exception("No pageFound")
def open_or_refresh(file_name):
file_name = "".join ([f if f in r'\/:*?"<>|' else urllib.quote(f) for f in file_name])
file_name = 'file:///' + file_name.replace('\\', '/')
file_name = file_name.encode('ascii', 'ignore')
try:
refresh_page(file_name)
except:
cmd = (r'"%(LOCALAPPDATA)s\Google\Chrome\Application\chrome.exe"'%os.environ
+ r' --remote-debugging-port=9222 "%s"' % file_name)
subprocess.Popen(cmd)
open_or_refresh(r"C:\test.html")
open_or_refresh(r"C:\test.html")
स्रोत
2012-07-05 12:53:18
मैं इस त्रुटि मिल रही देखें: [http://pastie.org/4208613](http://pastie.org/4208613) – prongs
मुझे यकीन है कि क्या गलत हो सकता है एक और सवाल हो रहा है नहीं कर रहा हूँ (एक पाउंड एक कसम जार में जा रहा है लेकिन मैं बस इतना कह सकता हूं कि यह मेरे लिए काम करता है।) –
अगर मैंने open_or_refresh (आर "सी: \ test.html") को 'open_or_refresh (u "सी में बदल दिया है तो मुझे एक ही त्रुटि मिल गई है : \\ test.html ") 'आपको एसीआई में होने वाली स्ट्रिंग की आवश्यकता है। –