自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(103)
  • 收藏
  • 关注

原创 出现IndentationError: unexpected indent或者TabError: inconsistent use of tabs and spaces异常的情况及解决方法

for i in range(10): print(i) print(i)File "<stdin>", line 3print(i)^IndentationError: unexpected indent1.IndentationError: unexpected indent2.TabError: inconsistent use of tabs and ...

2020-04-02 08:22:02 1387

原创 HTTP协议之Cookie和Session

Http是无状态协议,那么服务端如何识别特定的客户端呢?注:无状态指HTTP协议自身不对请求和响应之间的通信状态进行保存。对发送过的请求和响应都不做持久化处理(即不做任何保存)每次HTTP请求的时候,客户端都会发送相应的Cookie信息到服务端。实际上大多数的应用都是用Cookie来实现Session跟踪的,第一次创建Session的时候,服务端会在HTTP协议中告诉客户端,需要在Cooki...

2019-10-23 07:36:03 371

原创 Python文件操作之读取文件中的tuple、list、dict

Python读取文件,读取到的是str类型的内容,如果文件中是一个tuple、list或dict,无法直接使用,需要怎么转化呢?举个例子:b.txt的内容为[1,2,3]with open("d:\\document\\test\\b.txt") as fp: content = fp.read() print(content) print(type(content)...

2019-10-09 07:25:13 3432

原创 Python操作文件,报FileNotFoundError: [Errno 2] No such file or directory错误

with open("d:\\document\\test\\b.txt") as fp: content = fp.read() print(content)Python操作文件时,报No such file or directory错误。多次检查目录、文件名、语法都是对的。折腾一番后,发现是系统设置问题,设置的不展示文件扩展名,然后新建了一个b.txt文件,看起来文...

2019-10-09 07:10:38 45273 3

原创 Mysql5.7重置密码

5.7版本1、管理员权限登陆cmd,不会使用管理员登陆的请搜索cmd,搜索结果右键。2、命令行输入:net stop mysql;然后提示。服务停止中 --> 服务已停止。打开服务 win+R --> services.msc --> 回车,找到mysql开头的服务名。在服务中查看服务具体名称,比如mysql57。这里停掉服务再执行这一行3、由于mysqld –ski...

2019-09-29 07:19:02 430

原创 Python操作mysql增删改查

打开数据库连接import pymysqlconn = pymysql.connect( host = "127.0.0.1", port = 3306, user = "root", passwd = "123456", db = "testdb", charset = "utf8") # 使用cursor()方法获取数据库的操...

2019-09-29 07:10:54 299

原创 Selenium自动化之获取定位到的元素的属性值,文本信息

例:<a id='111' class='test' href='https://www.baidu.com'>测试链接文本</a>element = getElement(driver,locator_method,locator_exp)#获取文本信息element.get_attribute(‘textContent’)#返回:测试链接文本#获取属性值...

2019-09-11 08:19:30 4143

原创 Selenium自动化之操作日期控件(二)定位点击

#操作日期控件,定位点击from selenium import webdriverimport unittest, time, tracebackfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver...

2019-08-13 08:14:13 2528

原创 Selenium自动化之操作日期控件(一)send_keys

#操作日期控件send_keysfrom selenium import webdriverimport unittest, time, tracebackfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdr...

2019-08-13 08:11:56 2865

原创 Selenium自动化之上传文件(二)键盘操作,复制剪贴板中的文件路径,回车提交

#使用键盘操作,复制剪贴板中的文件路径,回车提交,实现上传文件from selenium import webdriverimport unittestimport timeimport tracebackimport win32clipboard as wimport win32apiimport win32confrom selenium.webdriver.support.u...

2019-08-13 08:09:46 1423

原创 Selenium自动化之上传文件(一)定位输入框,send_keys

#上传文件,找到上传文件路径的输入框,send_keysfileBox.send_keys(“g:\test.txt”)from selenium import webdriverimport unittestimport timeimport tracebackfrom selenium.webdriver.support.ui import WebDriverWaitfrom s...

2019-08-13 08:07:19 1707

原创 Selenium自动化之下载设置

#自动化下载,下载设置from selenium import webdriverimport unittest, timeclass TestDemo(unittest.TestCase): def setUp(self): # 创建一个FirefoxProfile实例,用于存放自定义配置 profile = webdriver.FirefoxP...

2019-08-13 07:49:32 518

原创 Selenium自动化之JS增删改查操作元素的属性

#JS增删改查操作元素的属性#新增属性driver.execute_script(“arguments[0].%s=arguments[1]” %attributeName,elementObj, value)#修改属性driver.execute_script(“arguments[0].setAttribute(arguments[1],arguments[2])”, elemen...

2019-08-13 07:27:00 3403

原创 Selenium自动化之使用操作系统命令杀掉浏览器进程

#使用操作系统命令杀掉浏览器进程import os#执行成功返回0os.system(“taskkill /F /iM iexplore.exe”)from selenium import webdriverimport unittestimport osclass VisitSogouByIE(unittest.TestCase): def test_killWindo...

2019-08-13 07:18:59 1072

原创 Selenium自动化之操作关键词联想浮层(二)使用xpath定位

#用xpath定位联想浮层,点击操作driver.find_element_by_xpath("//*[@id=‘vl’]/div[1]/ul/li[3]")from selenium import webdriverfrom selenium.common.exceptions import NoSuchElementExceptionimport tracebackimport un...

2019-08-13 07:11:49 728

原创 Selenium自动化之操作关键词联想浮层(一)使用键盘按键

#操作关键词联想浮层,键盘向下按键Keys.DOWNsearchBox.send_keys(Keys.DOWN)from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport unittestimport timeclass TestDemo(unittest.TestCase):...

2019-08-13 07:07:33 618

原创 Selenium自动化之利用JS操作滚动条

#利用JS操作滚动条#将页面的滚动条滑动到页面的最下方driver.execute_script(“window.scrollTo(0, document.body.scrollHeight);”)#滚动到第501个a标签driver.execute_script(“document.getElementsByTagName(‘a’)[500].scrollIntoView(true);”...

2019-08-12 08:09:10 1153

原创 Selenium自动化之JS操作

#使用JS操作,如果webdriver操作不了,就用这个#使用webdriver经常会有定位不到或者操作不了元素的情况,用JS来操作基本就不会有问题from selenium import webdriverfrom selenium.common.exceptions import WebDriverExceptionimport unittestimport tracebackim...

2019-08-12 08:01:57 672

原创 Selenium自动化之设置超时

#设置超时,比如访问国外网站超时后,进行下一步操作driver.set_page_load_timeout(4)import unittestimport timefrom selenium import webdriverfrom selenium.webdriver import ActionChainsfrom selenium.common.exceptions import ...

2019-08-12 07:56:30 2045

原创 Selenium自动化之操作cookies

#操作cookiesimport unittestimport timefrom selenium import webdriverfrom selenium.webdriver import ActionChainsclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 ...

2019-08-12 07:46:02 468

原创 Selenium自动化之操作js弹出框(弹窗)

#操作js弹出框,alert、confirm、prompt都是一样的操作alert = driver.switch_to.alertalert.accept()alert.dismiss()import unittestimport timefrom selenium import webdriverfrom selenium.webdriver import ActionChain...

2019-08-12 07:38:51 3829

原创 Selenium自动化之显式等待

#显式等待,元素判断from selenium.webdriver.support import expected_conditions as EC#显式等待input_box可见,再进行下一步操作wait.until(EC.visibility_of(input_box))#显示等待id为"stb"的元素可点击,再进行下一步操作wait.until(EC.element_to_be_c...

2019-08-12 07:34:00 443

原创 Selenium自动化之隐式等待

#隐式等待,driver.implicitly_wait(10),对所有元素生效,一般用于等待网页加载完成import unittestimport timefrom selenium import webdriverfrom selenium.webdriver import ActionChainsclass VisitSogouByIE(unittest.TestCase): ...

2019-08-12 07:28:52 545

原创 Selenium自动化之判断元素是否存在

#判断元素是否存在,driver.find_element(by=by, value=value),找不到这个元素则报异常import unittestimport timefrom selenium import webdriverfrom selenium.webdriver import ActionChainsclass VisitSogouByIE(unittest.Test...

2019-08-12 07:25:39 8500

原创 Selenium自动化之鼠标悬停操作

#鼠标悬停,move_to_element,光标移到指定元素上,停留几秒from selenium.webdriver import ActionChainsActionChains(self.driver).move_to_element§.perform()time.sleep(2)import unittestimport timefrom selenium import web...

2019-08-10 08:38:27 2997

原创 Selenium自动化之鼠标左键操作(按下,松开)

#鼠标左键按下、松开操作from selenium.webdriver import ActionChainsActionChains(self.driver).click_and_hold(div).perform()ActionChains(self.driver).release(div).perform()import unittestimport timefrom selen...

2019-08-10 08:34:45 4684

原创 Selenium自动化之鼠标右键操作,右键+P(粘贴),仅支持ie浏览器

#鼠标右键,输入框右键P=Ctrl+V粘贴,仅支持ie浏览器from selenium.webdriver import ActionChains#在搜索输入框上执行一个鼠标右键点击操作ActionChains(self.driver).context_click(searchBox).perform()import unittestimport timefrom selenium i...

2019-08-10 08:30:15 1605 3

原创 Selenium自动化之模拟键盘操作(二)组合键操作

#键盘操作,使用组合键,复制粘贴等import unittestfrom selenium import webdriverfrom selenium.webdriver import ActionChainsfrom selenium.webdriver.common.keys import Keysimport win32clipboard as wimport win32con...

2019-08-10 08:19:44 938

原创 Selenium自动化之模拟键盘操作(一)单键操作

#模拟键盘操作from selenium.webdriver.common.keys import Keyselement.send_keys(Keys.F12)element.send_keys(Keys.ENTER)import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unitt...

2019-08-10 08:12:01 997

原创 Selenium自动化之拖拽元素操作

**#拖拽元素#导入提供拖拽元素方法的模块ActionChainsfrom selenium.webdriver import ActionChains将页面上第一个能被拖拽的元素拖拽到第二个元素位置action_chains.drag_and_drop(initialPosition, targetPosition).perform()#将dragElement元素往右下角拖拽10个像...

2019-08-10 08:07:16 3452

原创 Selenium自动化之截屏自动化,以时间年月日创建文件夹,并以时分秒保存截图

#以时间年月日创建文件夹,并以时分秒保存截图图片import osimport os.pathimport timefrom selenium import webdriverurls=["http://www.baidu.com","http://www.sogou.com","http://cn.bing.com"]dir_name=time.strftime("%Y-%m-%...

2019-08-10 08:01:31 502

原创 Selenium自动化之截屏截取整个屏幕内容

#截屏,与前面只能截取浏览器页面不同,这个方法截取整个屏幕(显示器)的内容需先装pillow包py -3 -m pip install pillowfrom PIL import ImageGrabim=ImageGrab.grab()im.save("1.jpg","jpeg")...

2019-08-09 07:58:18 1224

原创 Selenium自动化之截屏操作

#截屏,截取整个网站页面import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 self.driver = webdriver.Ie(executable_p...

2019-08-09 07:54:27 347

原创 Selenium自动化之复选框操作

#复选框操作import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 self.driver = webdriver.Ie(executable_path="...

2019-08-09 07:48:58 1130

原创 Selenium自动化之单选框操作

#单选框操作import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 self.driver = webdriver.Ie(executable_path="g...

2019-08-09 07:45:53 1232

原创 Selenium自动化之操作有输入框的下拉框

#操作有输入框的下拉框import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 self.driver = webdriver.Ie(executable_pa...

2019-08-09 07:43:07 1606

原创 Selenium自动化之下拉框多选操作

#下拉框多选操作import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 self.driver = webdriver.Ie(executable_path=...

2019-08-09 07:40:35 1053

原创 Selenium自动化之另一种选中下拉框选项的方法

#另一种选中下拉框选项的方法import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 self.driver = webdriver.Ie(executable...

2019-08-09 07:36:23 1082 1

原创 Selenium自动化之点击下拉框选项操作

#点击下拉框选项option.click()import unittestimport timefrom selenium import webdriverclass VisitSogouByIE(unittest.TestCase): def setUp(self): # 启动IE浏览器 self.driver = webdriver.Ie(e...

2019-08-09 07:29:57 4738

原创 Selenium自动化之鼠标双击操作

#鼠标双击操作from selenium.webdriver import ActionChainsaction_chains = ActionChains(self.driver)action_chains.double_click(inputBox).perform()import unittestimport timefrom selenium import webdriver...

2019-08-09 07:19:28 3295

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除