python语言基础:
python语言是一个动态的,面对对象的,大小写敏感的脚本语言。
人生苦短,我用python:
1.简单:python是一种代表着极简主义思想的语言。
2.易学:python极容易上手。
3.速度快:编写速度快,运行速度快,数字无边界。
4.免费,开源。
变量:
a = 3
a 是一个变量,可以用任何字母代替(除了保留字)
3 是一个值,在 a 中有三个属性,id,type,value
其中id:39674664L,type:int,value:3
数据类型:
字符串型(str),整型(int),布尔型(False,Ture)浮点数型。
逻辑:
if 。。。else
for
#if循环
a = int(input(“请输入年的年份:”))
if a %40 and a%100!=0:
print (“闰年1”)
elif a%4000:
print (“闰年2”)
elif a%32000 and a %1728000:
print (“闰年3”)
else:
print (“不是闰年”)
#for循环
import turtle
t = turtle.Pen()
for i in range(360):
t.forward(i)
t.right(40)
对象:
字符串,字典,元组,列表
UI自动化:
工具:
range(x,y,step) 范围函数
random.randint 随机数函数
time.sleep 时间函数
webdriver 打开网站程序函数
在python打开网站的重要的两步:
1.进入python打开终端控制台Terminal
输入 pip install selenium 安装selenium模块
导入selenium中的webdriver
2.安装Firefox 的驱动 geckodriver:
下载完成后进行解压,然后将geckodriver.exe分别移动到python根目录和Firefox的根目录即可。
#打开百度网站且搜索关键字,打印出搜索结果,也可以说雇佣了一个robot来打开网站。
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get(‘http://www.baidu.com/’)
srk = driver.find_element_by_id(“kw”)
srk.send_keys(u"美女")
sou = driver.find_element_by_id(“su”)
sou.click()
time.sleep(10)
biaotis = driver.find_elements_by_tag_name(“h3”)
lianjie = driver.find_elements_by_tag_name(“a”)
for a in biaotis:
print (a.text)
for b in lianjie:
print (b.text)