Python Quick Start
1、安装Python
官网下载python: https://www.python.org/
有2.x 3.x版本, 注意,python3.0不向下兼容2.x版本,有很多包3.0不提供
下载完后直接点击安装即可。比如我的安装目录为:C:\Python27
然后配置系统环境:我的电脑 —>属性—>高级—>环境变量—>系统变量
设置Path,将你的python的安装路径 “C:\Python27” 写入Path变量中即可
在控制台打python命令, 出现如下提示表示配置成功:
2、安装python IDE
Eclipse plugin,(http://pydev.org/updates)
1)直接在Eclipse中选择菜单:Help—Install New Updates—And,输入http://pydev.org/updates,下载并安装。
(完成后再启动Eclipse,可以在Eclipse菜单Help->About Eclipse SDK->Installation Detail看到PyDev组件的安装)
2)在Eclipse菜单Windows->Preferences->PyDev->Interpreter python配置你要只用的python解析器。点击New按钮,从Python的安装路径下选择Python.exe。
3、python安装模块(方法一)
Python很多第三方模块可以直接拿来使用
下面以Python language bindings for Selenium WebDriver.为例,说明开发python时,怎么使用第三方提供的对象等
1)https://pypi.python.org/pypi/selenium 下载selenium-2.41.0.tar.gz
2)解压该文件, 再到包含setup.py的目录下执行: (Python第三方模块中一般会自带setup.py文件)
python setup.py install
表示已经成功install
安装的过程中可能会出现“ImportError: No module named setuptools”的错误提示,这是因为Python默认没有安装setuptools这个模块的,这也是一个第三方模块。下载地址为http://pypi.python.org/pypi/setuptools
先安装setuptools,再重新install selenium即可
注: install完成后, 在C:\Python27\Lib\site-packages 目录下, 多出了selenium-2.41.0-py2.7.egg 目录。
4、python安装模块(方法二)
pip 是一个安装和管理 Python 包的工具, 所以python安装模块也可以借助pip工具来直接install, 这种方式可以不用先去下载包, 直接在线完成安装。
借助pip之前, 先安装pip, 地址https://pypi.python.org/pypi/pip#download , 安装pip可采用上面方法一,安装完成后,配置pip环境变量“C:\Python27\Scripts”
安装完pip后, 就可以借助pip 安装、升级、卸载 python第三方模块,如:
pip install -U selenium
pip install goslate
pip install simplejson
pip uninstall simplejson
pip install --upgrade simplejson......
5、python开发selenium脚本简单示例
# coding=gb2312
'''
Created on 2014-05-14
@author: jennifer.huang
'''
from selenium import webdriver
from selenium.webdriver.common.by import By keyword="selenium python"
try:
browser = webdriver.Chrome("chromedriver.exe")
browser.get("http://www.baidu.com")
browser.find_element(By.ID, "kw1").send_keys(keyword)
browser.find_element(By.ID, "su").submit()
print browser.find_element(By.ID, "kw").get_attribute("value")
assert keyword in browser.find_element(By.ID, "kw").get_attribute("value")
except KeyboardInterrupt:
print "ended by user"
finally:
browser.quit()
对比下java语言的写法:
package com.jennifer.tests;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; public class SeleniumJava {
WebDriver driver;
@Before
public void init(){
driver = new FirefoxDriver();
}
String keyword="selenium python";
@Test
public void test(){
driver.get("http://www.baidu.com");
driver.findElement(By.id("kw1")).sendKeys(keyword);
driver.findElement(By.id("su")).submit();
System.out.println(driver.findElement(By.id("kw")).getAttribute("value"));
Assert.assertEquals(driver.findElement(By.id("kw")).getAttribute("value"), keyword);
}
@After
public void tearDown(){
driver.quit();
} }
Python Quick Start的更多相关文章
- Python Quick list dir
昨天 Python释放了 3.5 ,添加了 os.scandir 根据文档该API比os.listdir快Docs which speeds it up by 3-5 times on POSIX s ...
- Why Python is Slow
Why Python is Slow: Looking Under the Hood https://jakevdp.github.io/blog/2014/05/09/why-python-is-s ...
- Quick Reference Card Urls For Web Developer
C# C# Cheatsheet & Notes Coding Guidelines for C# 3.0, 4.0, 5.0 Core C# and .NET Quick Reference ...
- OpenSSL重大漏洞-Heartbleed之漏洞利用脚本POC讲解
OpenSSL Security Advisory [07 Apr 2014] ======================================== TLS heartbeat read ...
- OpenSSL "heartbleed" 安全漏洞
在 heartbleed 的官网上有关于 CVE-2014-0160 漏洞的详细信息,这是关于 OpenSSL 的信息泄漏漏洞导致的安全问题.改 Heartbleed bug 可以让互联网的任何人读取 ...
- Practical Web Penettation Testing (the first one Mutillidae 大黄蜂)
1.now we looke at this book . I decide to make a brief review the book covers as follows (I straigh ...
- TensorFlow学习路径【转】
作者:黄璞链接:https://www.zhihu.com/question/41667903/answer/109611087来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- TensorFlow学习线路
如何高效的学习 TensorFlow 代码? 或者如何掌握TensorFlow,应用到任何领域? 作者:黄璞链接:https://www.zhihu.com/question/41667903/ans ...
- MongoDB排序记录
MongoDB sort()方法 要在MongoDB中排序文档,需要使用sort()方法. 该方法接受包含字段列表及其排序顺序的文档.使用指定排序顺序1和-1. 1用于升序,而-1用于降序. 语法 s ...
随机推荐
- [置顶] 问题解决——XP线程池找不到QueueUserWorkItem
2013年7月11号 主管让同事写一个并发100的小工具进行什么压力测试,据说是创建100个线程. 我表示这真真的是在坑人! 线程创建消耗资源,以自己的笔记本来跑这个东西,时间片都消耗在了线程切换上了 ...
- Unity3D-Baked Lightmapping 示例学习
首先,看一下摄像机的Rendering Paths http://game.ceeger.com/Manual/RenderingPaths.html 可以看出,对于灯光的渲染质量 Deferred ...
- 五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT) – 整理
当Adobe.Microsoft.Sun等一系列巨头开始表现出对”开源”的青睐时,”开源”的时代即将到来! 最初来自:sinoprise.com/read.php?tid-662-page-e-fpa ...
- JTextField限制 输入数字
貌似有很多方法,先记了再说... 1.限制输入数字 用法 textfield.setDocument(new IntegerDocument()); class IntegerDocument ext ...
- 不可不表的OSG智能指针之强指针与弱指针 《转载》
不可不表的OSG智能指针之强指针与弱指针 <转载> 使用OSG的人都知道OSG的内存管理方式采用了智能指针,通过智能指针的方式让OSG自己处理对象的销毁工作.在OSG中有两个智能指针类型, ...
- TreeView节点拖拉操作
//这个拖拽的感觉不对 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, ...
- [AngularJS] Test an Angular Component with $componentController
Traditionally you had to create DOM elements to test a directive but by shifting our focus to compon ...
- [React] Styling React Components With Aphrodite
Aphrodite is a library styling React components. You get all the benefits of inline styles (encapsul ...
- C读取配置文件
#ifndef __CFG_OP_H__ #define __CFG_OP_H__ #ifdef __cplusplus extern "C" { #endif //获取配置项 i ...
- 将 Discuz X3 手机版默认的“标准版”改为“触屏版”
修改前请备份原文件 1.找到“\source\class\discuz\discuz_application.php”,将其中的 'mobiletpl' => array('1' =&g ...