Skip to content

Instantly share code, notes, and snippets.

View zoghal's full-sized avatar
🏠
Working from home

Saleh Souzanchi zoghal

🏠
Working from home
View GitHub Profile
@font-face {
font-family: 'irani';
src: url('/content/fonts/iran-sans.woff') format('woff');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'irani';
src: url('/content/fonts/iran-sans-bold.woff') format('woff');
@zoghal
zoghal / test.js
Last active August 29, 2015 14:21 — forked from JacksonTian/test.js
var Ghost = require('webghost');
var should = require('should');
var ghost = new Ghost({browser: "chrome", host: "ip"});
ghost.open()
.go("http://your/url")
.text('p', function (text) {
text.should.be.not.equal('haha');
})
.click('button') // 点击按钮
from ghost import Ghost
from PySide.QtGui import QApplication, QImage, QPainter, QPrinter
class MyGhost(Ghost):
def capture_pdf(self):
printer = QPrinter(QPrinter.HighResolution)
printer.setResolution(300)
printer.setOutputFileName("QtPrinter.pdf")
printer.setPaperSize(QPrinter.A4)
from ghost import Ghost
from sys import argv
def main():
url = argv[1]
path = argv[2]
screenshot(url,path)
def screenshot(url,path):
ghost = Ghost()
# Installation:
# pip install selenium && curl -O http://chromedriver.storage.googleapis.com/2.8/chromedriver_mac32.zip && unzip chromedriver_mac32.zip && mv ./chromedriver /usr/local/bin/chromedriver
# Resources:
# ChromeDriver: https://code.google.com/p/selenium/wiki/ChromeDriver
# ChromeDriver Getting Started: https://sites.google.com/a/chromium.org/chromedriver/getting-started
# Selenium Python: http://selenium-python.readthedocs.org/en/latest/api.html
from selenium import webdriver
from ghost import Ghost
from sys import argv
def main():
url = argv[1]
path = argv[2]
screenshot(url,path)
def screenshot(url,path):
ghost = Ghost()
@zoghal
zoghal / selenium.py
Last active August 29, 2015 14:21 — forked from pknam/selenium.py
__author__ = 'pknam'
from selenium import webdriver
import time
def main():
# browser = webdriver.PhantomJS(executable_path=r"D:\selenium_drivers\phantomjs-2.0.0-windows\bin\phantomjs.exe")
# browser = webdriver.Ie(executable_path=r"D:\selenium_drivers\Internet Explorer(x64)\IEDriverServer.exe")
browser = webdriver.Chrome(executable_path=r"D:\selenium_drivers\Chrome(x86)\chromedriver.exe")
'''
You'll need to install npm, nodejs and phantomjs
$ apt-get install nodejs nodejs-dev npm phantomjs
$ pip install selenium-python
'''
from selenium import webdriver
from PIL import Image
import datetime
filename = "miri_regev_"+datetime.datetime.now().strftime("%Y.%m.%d.%H:%M:%S")+".png"
fox = webdriver.Firefox()
fox.get('https://www.facebook.com/miri.regev.il')
fox.save_screenshot(filename) # saves screenshot of entire page
fox.quit()

#Webpage Thumbnails In Python A small WSGI script that uses selenium's headless PhantomJS driver to capture webpage screenshots, and PIL to resize them. Cropping options could easily be added.

##Dependencies

  • Python selenium
  • Python PIL
  • PhantomJS