splinter安装

 Splinter:Splinter is an open source tool for testing web applications using Python. It lets you automate browser actions, such as visiting URLs and interacting with their items.


 1027  pip install splinter

 1028  cd opt
 1029  git clone git://github.com/cobrateam/splinter.git
 1030  ll
 1031  cd splinter
 1032  ll
 1033  python setuppy.install
 1034  python setup.py install
 1035  python 
 1036  pip install splinter[zope.testbrowser]
 1037  cd /
 1039  cd opt
 1040  wget https://pypi.python.org/pypi/lxml/3.4.0#downloads
 1041  ll 
 1042  wget https://pypi.python.org/pypi/lxml/3.4.0#downloads
 1043  wget https://pypi.python.org/packages/source/l/lxml/lxml-3.4.0.tar.gz#md5=bc90cc4e4ee04e1f8290ae0f70e34eea

 lxml是python的一个html/xml解析并建立dom的库(dom文档对象模型)

 1046  tar -zxvf lxml-3.4.0.tar.gz 

 1047  cd lxml-3.4.0
 1048  ll 

 1049  python setup.py install

vi splinter.py

#!/usr/bin/python
# SPLint output colorizer
#
# This script runs SPLint with a given set of arguments and colorizes the
# output to improve readability.
import sys
import os
import re
# Colors for printing
colors = {
    'red' : '\033[31m',
    'green' : '\033[32m',
    'yellow'    : '\033[33m',
    'blue' : '\033[34m',
    'magenta'    : '\033[35m',
    'cyan' : '\033[36m',
    'white' : '\033[37m'
}
# This is where the compiled regexes will get stored soon
regexes = {}
# Hook to colorize the Splint title line. This is useful, because it helps you
# find the beginning of last run's output.
def title_hook(line):
    print colors["green"]
    x = "#" * len(line)
    print x
    print line
    print x + "\033[0m"
# Hook to colorize Splint's function names
def funcname_hook(line):
    fre = re.compile("(.*\(in function )(.*)(\).*)")
    obj = fre.match(line)
    if (obj is not None):
        print obj.group(1) + colors["magenta"] + obj.group(2) + "\033[0m" + obj.group(3)
# Hook to colorize error messages
def error_hook(line):
    print colors["red"] + line + "\033[0m"
# Hook to colorize explainatory text
def explaination_hook(line):
    print colors["blue"] + line + "\033[0m"
def info_hook(line):
    print colors["cyan"] + line + "\033[0m"
hooks = {
    'title' : title_hook,
    'funcname' : funcname_hook,
    'error' : error_hook,
    'expl' : explaination_hook,
    'info' : info_hook
}
# Uncompiled regexes. This is what we look for in Splint's output and then
# call hook functions (see @hooks below...) to do whatever we want with this
# line
regex_uncompiled = {
    'title' : "Splint \d\..*",
    'funcname' : ".*\(in function .*\).*",
    'error' : "\s{4,4}\S.*",
    'expl' : "\s{2,2}\S.*",
    'info' : "Command Line:.*"
}
### START OF SCRIPT ###
# Compile the regexes
for reg in regex_uncompiled.keys():
    regexes[reg] = re.compile(regex_uncompiled[reg])
# build cmd line
cmdline = ""
for param in sys.argv[1:]:
    cmdline += (" " + param)
print "Executing: ", cmdline
# Output will be redirected
# XXX: I'd prefer to read the output directly into this script?
cmdline += " >&_splint.out"
# execute splint
os.system(cmdline)
# read output and remove temp file
f = file("_splint.out")
output = f.readlines()
os.system("rm _splint.out")
# process output
for line in output:
# erase trailing newline
    l = line.strip("\n")
    seen = 0
# try to match this line with a regex
    for name in regexes:
        if regexes[name].match(l):
            seen = 1
            hooks[name](l)
            break
# if no regex matched, simply print
    if seen == 0:
        print l


cp 至/usr/bin 下,执行 from splinter import Browser,报错 ImportError:cannot import name Browser

yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel
运行后依然报错
Type "help", "copyright", "credits" or "license" for more information.
>>> from splinter.browser import Browser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/splinter-0.6.0-py2.6.egg/splinter/__init__.py", line 6, in <module>
    from splinter.browser import Browser
  File "/usr/lib/python2.6/site-packages/splinter-0.6.0-py2.6.egg/splinter/browser.py", line 12, in <module>
    from splinter.driver.webdriver.phantomjs import WebDriver as PhantomJSWebDriver
  File "/usr/lib/python2.6/site-packages/splinter-0.6.0-py2.6.egg/splinter/driver/webdriver/phantomjs.py", line 1, in <module>
    from selenium.webdriver import PhantomJS, DesiredCapabilities
ImportError: cannot import name PhantomJS

发布了226 篇原创文章 · 获赞 38 · 访问量 45万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览