Created
February 22, 2012 06:49
-
-
Save xkyii/1882537 to your computer and use it in GitHub Desktop.
My Python Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide.QtWebKit import * | |
class Scrape(QApplication): | |
def __init__(self): | |
print('init') | |
super(Scrape, self).__init__(sys.argv) | |
self.webView = QWebView() | |
self.webView.show() | |
self.webView.loadFinished.connect(self.searchForm) | |
def load(self, url): | |
print('load') | |
self.webView.load(QUrl(url)) | |
def searchForm(self): | |
print('searchForm') | |
documentElement = self.webView.page().currentFrame().documentElement() | |
inputSearch = documentElement.findFirst('input[name=q]') | |
print('inputSearch.isNull: '+str(inputSearch.isNull())) | |
inputSearch.setAttribute('value', 'test') | |
form = documentElement.findFirst('form[name=f]') | |
form.evaluateJavaScript('this.submit()') | |
print('form.isNull: '+str(form.isNull())) | |
print('searchForm end') | |
self.webView.loadFinished.disconnect(self.searchForm) | |
self.webView.loadFinished.connect(self.searchResults) | |
def searchResults(self): | |
print('searchResults') | |
#documentElement = self.webView.page().currentFrame().documentElement() | |
#for element in documentElement.findAll('li[class=g]'): | |
# print(unicode(element.toOuterXml())) | |
#self.exit() | |
app = Scrape() | |
app.load('http://www.google.com.hk') | |
sys.exit(app.exec_()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: gbk -*- | |
# code by vkyii | |
# email: [email protected] | |
# hg push | |
# file <.hg/hgrc> need user_name and password | |
# [paths] | |
# default = https://user_name:password@your_project_address | |
import subprocess | |
hg = '''"C:\Program Files\TortoiseHg\hg.exe"''' | |
hg_dirs = ['prj1', 'prj2', 'prj3'] #projects which include .hg directory | |
def hg_push(directory): | |
p = subprocess.Popen(hg+" push", cwd=directory, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
for line in p.stdout.readlines(): | |
print line, | |
retval = p.wait() | |
if __name__ == "__main__": | |
base_dir = "./" | |
#base_dir = "../../" | |
for directory in hg_dirs: | |
hg_push(base_dir+directory); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide.QtWebKit import * | |
app = QApplication(sys.argv) | |
web = QWebView() | |
web.settings().setAttribute( | |
QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) | |
# or globally: | |
# QWebSettings.globalSettings().setAttribute( | |
# QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) | |
web.load(QUrl("http://www.google.com")) | |
web.show() | |
inspect = QWebInspector() | |
inspect.setPage(web.page()) | |
inspect.show() | |
sys.exit(app.exec_()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://pypi.python.org/pypi/selenium#downloads | |
from selenium import webdriver | |
from selenium.common.exceptions import NoSuchElementException | |
from selenium.webdriver.common.keys import Keys | |
import time | |
browser = webdriver.Firefox() # Get local session of firefox | |
browser.get("http://www.yahoo.com") # Load page | |
assert "Yahoo!" in browser.title | |
elem = browser.find_element_by_name("p") # Find the query box | |
elem.send_keys("seleniumhq" + Keys.RETURN) | |
time.sleep(0.2) # Let the page load, will be added to the API | |
try: | |
browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]") | |
except NoSuchElementException: | |
assert 0, "can't find seleniumhq" | |
browser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment