分类 python 下的文章

环境:python2.7,pip 1.5.4

pip install aliyun-python-sdk-core==2.3.5 aliyun-python-sdk-rds datetime
#报错
The 'pip==7.1.0' distribution was not found and is required by the application

https://files.pythonhosted.org/packages/07/9d/2af576b8b199c69d839a8dfd6025b6721a18a0b771a051b2b62b3c866d0f/distribute-0.6.10.tar.gz
tar -zxvf distribute-0.6.10.tar.gz
cd  distribute-0.6.10
python setup.py install

easy_install pip==7.1.0

pip install aliyun-python-sdk-core==2.3.5 aliyun-python-sdk-rds datetime

pip install selenium
脚本

#!/usr/bin/python
from selenium import webdriver
browser = webdriver.PhantomJS()
browser.get("http://www.site-digger.com/html/articles/20110516/proxieslist.html")
trs = browser.find_elements_by_tag_name('tr')
for tr in trs[1:]:
        print(tr.text.split(' ')[0])

报 selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar -xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 
cp -R phantomjs-2.1.1-linux-x86_64 /usr/local/share/ 
ln -sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/

- 阅读剩余部分 -

应用场景:一些定时任务脚本,要求不能多个同时运行,当下一下定时时间到来,当前脚本没有运行完成,就可能重复。

def is_runing(process_name):
        try:
                process = len(os.popen('ps aux | grep "' + process_name + '" | grep -v grep').readlines())
                if process > 1:
                        return 1
                else:
                        return 0
        except:
                return 0

大于1,是因为在执行 ps aux | grep "' + process_name + '" 的时候,同一时间这个本身就是一个进程,因为用等于一是不行的。