def setupBrowser(self): self.browser = WebView() self.browser.show() self.browser.open(self.url) self.scroller = ScrolledWindow() self.scroller.add(self.browser) self.window.add(self.scroller) self.browser.connect("title-changed", self.title_changed) self.scroller.show()
class TestWebFrame(unittest.TestCase): def setUp(self): gobject.threads_init() self.view = WebView() self.mainFrame = self.view.get_main_frame() def testloaduri(self): self.mainFrame.load_uri("about:blank") self.assertEqual("about:blank", self.mainFrame.get_uri()) def tearDown(self): self.view.destroy()
def __init__(self): gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) # Fixed Container self.fixed = gtk.Fixed() self.add(self.fixed) # Get Screen Info self.width = width = gtk.gdk.screen_width() self.height = height = gtk.gdk.screen_height() # Label self.label = gtk.Label() self.label.set_justify(gtk.JUSTIFY_LEFT) self.label.set_usize(width, 50) self.label.set_label(ip.ipaddress()) self.fixed.put(self.label, 0, height-50) # WebView self.webview = WebView() self.webview.set_usize(width, height - 50) self.fixed.put(self.webview, 0, 0) self.loadUrls() self.fullscreen() self.open() self.hadnuimoaction = False self.showIpAddress() thread = threading.Thread(target=self.auto_loop) thread.daemon = True thread.start()
class TestWebBackForwardList(unittest.TestCase): """Test WebBackForwardList functions""" def setUp(self): gobject.threads_init() self.view = WebView() self.bf_list = self.view.get_back_forward_list() def testadditem(self): item = WebHistoryItem(uri="http://example.com/", title="Example1") self.bf_list.add_item(item) self.assertEqual(item, self.bf_list.get_current_item()) currentItem = self.bf_list.get_current_item() self.assertEqual("Example1", currentItem.get_title()) self.assertEqual("http://example.com/", currentItem.get_uri()) def testbackforwardlistwithlimit(self): item1 = WebHistoryItem(uri="http://example.com/1/", title="Example1") item2 = WebHistoryItem(uri="http://example.com/2/", title="Example2") item3 = WebHistoryItem(uri="http://example.com/3/", title="Example3") item4 = WebHistoryItem(uri="http://example.com/4/", title="Example4") self.bf_list.add_item(item1) self.bf_list.add_item(item2) self.bf_list.add_item(item3) self.bf_list.add_item(item4) backList = list() backList = self.bf_list.get_back_list_with_limit(10) self.assertTrue(backList is not None) self.assertEqual("Example4", self.bf_list.get_current_item().get_title()) self.assertEqual("Example3", backList[0].props.title) self.assertEqual("Example2", backList[1].props.title) self.assertEqual("Example1", backList[2].props.title) self.bf_list.go_to_item(item1) self.assertEqual(self.bf_list.get_current_item().get_title(), item1.get_title()) forwardList = list() forwardList = self.bf_list.get_forward_list_with_limit(10) self.assertTrue(forwardList is not None) self.assertEqual("Example4", forwardList[0].props.title) self.assertEqual("Example3", forwardList[1].props.title) self.assertEqual("Example2", forwardList[2].props.title) def testclearbackforwardlist(self): item1 = WebHistoryItem(uri="http://example.com/1/", title="Example1") item2 = WebHistoryItem(uri="http://example.com/2/", title="Example2") self.bf_list.set_limit(0) self.bf_list.set_limit(1) self.bf_list.add_item(item2) self.assertEqual(self.bf_list.get_back_length(), 0) self.assertEqual(self.bf_list.get_forward_length(), 0) self.assertEqual(self.bf_list.get_current_item(), item2) def tearDown(self): # nothing here. pass
def __init__(self): WebView.__init__(self) self.load_finish_flag = False self.set_property('can-focus', True) self.set_property('can-default', True) self.set_full_content_zoom(1) self.clipbord = gtk.Clipboard() settings = self.get_settings() try: settings.set_property('enable-universal-access-from-file-uris', True) settings.set_property('javascript-can-access-clipboard', True) settings.set_property('enable-default-context-menu', True) settings.set_property('enable-page-cache', True) settings.set_property('tab-key-cycles-through-elements', True) settings.set_property('enable-file-access-from-file-uris', True) settings.set_property('enable-spell-checking', False) settings.set_property('enable-caret-browsing', False) try: # Since 1.7.5 settings.set_property('enable-accelerated-compositing', True) except TypeError: pass except: print 'Error: settings property was not set.' webkit.set_web_database_directory_path(config.DB_DIR) webkit.set_default_web_database_quota(1024**3L) ## bind events self.connect('navigation-requested', self.on_navigation_requested) self.connect('new-window-policy-decision-requested', self.on_new_window_requested) self.connect('script-alert', self.on_script_alert) self.connect('load-finished', self.on_load_finish) self.connect("hovering-over-link", self.on_over_link) # self.connect('drag_data_received', self.on_drag_data_received) # self.connect('drag_motion', self.on_drag_motion) # self.connect('drag_drop', self.on_drag_drop) # self.drag_dest_set(gtk.DEST_DEFAULT_DROP, # dnd_list, gtk.gdk.ACTION_COPY) templatefile = utils.get_ui_object(config.TEMPLATE) template = open(templatefile, 'rb').read() self.load_html_string(template, 'file://' + templatefile)
class Dan: def __init__(self): self.url = "http://www.bibud.com" self.setupWindow() self.setupBrowser() main() def setupWindow(self): self.window_title = "Bibud" self.window = Window() self.window.show() self.window.connect("destroy-event", self.browser_quit) self.window.resize(1024, 768) self.window.set_title(self.window_title) def setupBrowser(self): self.browser = WebView() self.browser.show() self.browser.open(self.url) self.scroller = ScrolledWindow() self.scroller.add(self.browser) self.window.add(self.scroller) self.browser.connect("title-changed", self.title_changed) self.scroller.show() def eTitleChanged(self, webview, frame, title): self.window.set_title(title) def eQuit(self): main_quit()
class Dan: def __init__(self): self.url = "http://www.bibud.com" self.setupWindow() self.setupBrowser() main() def setupWindow(self): self.window_title = "Bibud" self.window = Window() self.window.show() self.window.connect("destroy-event", self.browser_quit) self.window.resize(1024,768) self.window.set_title(self.window_title) def setupBrowser(self): self.browser = WebView() self.browser.show() self.browser.open(self.url) self.scroller = ScrolledWindow() self.scroller.add(self.browser) self.window.add(self.scroller) self.browser.connect("title-changed", self.title_changed) self.scroller.show() def eTitleChanged(self, webview, frame, title): self.window.set_title(title) def eQuit(self): main_quit()
def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) sw = gtk.ScrolledWindow() self.view = WebView() sw.add(self.view) window.add(sw) self.loadUrls() window.fullscreen() window.show_all() self.view.open(self.urls[self.current]) self.hadnuimoaction = False thread = threading.Thread(target=self.auto_loop) thread.daemon = True thread.start()
class App: def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) sw = gtk.ScrolledWindow() self.view = WebView() sw.add(self.view) window.add(sw) self.loadUrls() window.fullscreen() window.show_all() self.view.open(self.urls[self.current]) self.hadnuimoaction = False thread = threading.Thread(target=self.auto_loop) thread.daemon = True thread.start() def loadUrls(self): self.current = 0 urlsPath = 'urls.csv' if len(sys.argv) > 1: urlsPath = sys.argv[1] try: with open(urlsPath) as f: self.urls = f.readlines() #remove empties self.urls = filter(None, self.urls) except: print 'failed to read ' + urlsPath self.urls = ['http://google.com'] def next(self): self.current = (self.current + 1) % len(self.urls) self.view.open(self.urls[self.current]) def previous(self): self.current = self.current - 1 if self.current < 0: self.current = len(self.urls) - 1 self.view.open(self.urls[self.current]) def auto_loop(self): sleep = 18 if len(sys.argv) > 2: sleep = float(sys.argv[2]) while True: time.sleep(sleep) if self.hadnuimoaction == False: gtk.idle_add(self.next) else: self.hadnuimoaction = False
def setUp(self): gobject.threads_init() self.view = WebView() self.mainFrame = self.view.get_main_frame()
def __init__(self): WebkitWebView.__init__(self) self.set_full_content_zoom(True)
class MainWindow(gtk.Window): def __init__(self): gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) # Fixed Container self.fixed = gtk.Fixed() self.add(self.fixed) # Get Screen Info self.width = width = gtk.gdk.screen_width() self.height = height = gtk.gdk.screen_height() # Label self.label = gtk.Label() self.label.set_justify(gtk.JUSTIFY_LEFT) self.label.set_usize(width, 50) self.label.set_label(ip.ipaddress()) self.fixed.put(self.label, 0, height-50) # WebView self.webview = WebView() self.webview.set_usize(width, height - 50) self.fixed.put(self.webview, 0, 0) self.loadUrls() self.fullscreen() self.open() self.hadnuimoaction = False self.showIpAddress() thread = threading.Thread(target=self.auto_loop) thread.daemon = True thread.start() def showIpAddress(self): text = '<span weight="bold" size="xx-large">%s</span>' % ip.ipaddress() self.label.set_markup(text) self.webview.set_usize(self.width, self.height-50) def loadUrls(self): self.current = 0 urlsPath = 'urls.csv' def split(x): return map(str.rstrip, x.split(',')) if len(sys.argv) > 1: urlsPath = sys.argv[1] try: with open(urlsPath) as f: self.urls = map(split, f.readlines()) except: print 'failed to read ' + urlsPath self.urls = ['http://google.com', 'Google'] def open(self): self.rotating = False self.rotateval = 0 self.webview.set_usize(self.width, self.height) self.webview.open(self.urls[self.current][0]) def rotate(self, val): self.rotating = True self.rotateval += val count = len(self.urls) idx = (self.current + (self.rotateval / 100)) % count text = '%s (%d/%d)' % (self.urls[idx][1], idx+1, count) text = xml.sax.saxutils.escape(text) text = '<span weight="bold" size="xx-large">%s</span>'%(text) #print text self.label.set_markup(text) self.webview.set_usize(self.width, self.height-50) def next(self): count = len(self.urls) if self.rotating == False: self.current = (self.current + 1) % count else: self.current = (self.rotateval / 100) % count self.open() def previous(self): self.current = self.current - 1 if self.current < 0: self.current = len(self.urls) - 1 self.open() def auto_loop(self): sleep = 18 if len(sys.argv) > 2: sleep = float(sys.argv[2]) while True: time.sleep(sleep) if self.hadnuimoaction == False: gtk.idle_add(self.next) else: self.hadnuimoaction = False
def setUp(self): gobject.threads_init() self.view = WebView() self.bf_list = self.view.get_back_forward_list()
def __init__(self, domain): self.domain = domain self.view = WebView() self.frame = self.view.get_main_frame()
class Evaluator(object): _replacechars = u'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЪЭЮЯабвгдеёжзийклмнопрстуфхцчшщьъэюя' def __init__(self, domain): self.domain = domain self.view = WebView() self.frame = self.view.get_main_frame() def set_html(self, html, base_uri=''): self.view.load_html_string(html, base_uri) def reset_html(self): self.set_html(u'<html><head></head><body></body></html>') def eval_js(self, script): self.view.execute_script(script) # returns None def get_html(self): self.eval_js('document.title=document.documentElement.innerHTML;') html = self.frame.get_title() return unicode(html) def find_script(self, page): soup = BeautifulSoup(page) script = soup.body.find(text=re.compile(u'dеobfuscate_html\(\)')) s = unicode(script) return s def deobfuscate_form(self, script): self.reset_html() self.eval_js(script) self.eval_js(u'captcha_div2.innerHTML=dеobfuscate_html();') return self.get_html() def _filter_markup(self, form): for c in self._replacechars: form = form.replace(c, '') return form def find_capair(self, form): '''Finds cahash on deobfuscated page.''' soup = BeautifulSoup(form) cahash = soup.body.find(attrs={'name': re.compile('cahash')}) if cahash: caimg = soup.body.find(attrs= {'src': re.compile(''.join(('\/a\d\.', self.domain, '\/i\/captcha\/')))}) if caimg: return [str(cahash.get('value')), str(caimg.get('src'))] else: raise exc.PermanentError('caimg not found in form') else: raise exc.PermanentError('cahash not found in form') def solve_capage(self, page): s = self.find_script(page) if s: form = self.deobfuscate_form(s) return self.find_capair(self._filter_markup(form)) else: raise exc.PermanentError('Obfuscated html not found in page')
def __init__(self): WebView.__init__(self) self.load_finish_flag = False self.set_property('can-focus', True) self.set_property('can-default', True) self.set_full_content_zoom(1) self.clipbord = gtk.Clipboard() settings = self.get_settings() try: settings.set_property('enable-universal-access-from-file-uris', True) settings.set_property('javascript-can-access-clipboard', True) settings.set_property('enable-default-context-menu', True) settings.set_property('enable-page-cache', True) settings.set_property('tab-key-cycles-through-elements', True) settings.set_property('enable-file-access-from-file-uris', True) settings.set_property('enable-spell-checking', True) settings.set_property('enable-caret-browsing', False) except: print 'Error: settings property was not set.' webkit.set_web_database_directory_path(config.DB_DIR) webkit.set_default_web_database_quota(1024**3L) ## bind events self.connect('navigation-requested', self.on_navigation_requested); self.connect('new-window-policy-decision-requested', self.on_new_window_requested); self.connect('script-alert', self.on_script_alert); self.connect('load-finished', self.on_load_finish); self.connect("hovering-over-link", self.on_over_link); templatefile = utils.get_ui_object(config.TEMPLATE) template = open(templatefile, 'rb').read() self.load_html_string(template, 'file://' + templatefile)