摘要: 1、文件的上传coding=utf-8from selenium import webdriverimport timeimport osbrowser=webdriver.FireFox()file_path='file:///'+os.path.abspath('upload_file.html')browser.get(file_path)browser.find_element_by_name('file').send_keys(C:\Python\selenium_case\upload_file.html) #定位上传按钮,添加本地文 阅读全文
posted @ 2014-04-07 19:03 junezhang 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 1、常用方法:点击对象、在对象上模拟按键输入、清除对象的内容、获取元素的文本、提交表单、获得属性值coding=utf-8from selenium import webdriverimport timebrowser=webdriver.FireFox()browser.get('http://www.baidu.com')browser.find_element_by_id('kw').clear() #清除对象的内容browser.find_element_by_id('kw').send_keys('selenium') 阅读全文
posted @ 2014-04-07 18:42 junezhang 阅读(499) 评论(0) 推荐(0) 编辑
摘要: 1、目的 操作对象、获得对象的属性值、获得对象的text、获得对象的数量2、单个对象定位方法:id、name、tag name、class name、CSS、XPath、Link Text、Partical Link Text用到的HTML文档 Form simple login form Email Password ... 阅读全文
posted @ 2014-04-07 17:27 junezhang 阅读(632) 评论(0) 推荐(0) 编辑
摘要: #打印URLcoding=utf-8from selenium import webdriverimport timebrowser=webdriver.FireFox()url='http://www.baidu.com'browser.get(url) #通过操作get()得到URLprint 'Title of current page is %s'%(browser.title) #打印当前页面titleprint 'URL of current page is %s'%(browser.url) #打印当前页面urlbrowser.qu 阅读全文
posted @ 2014-04-07 13:15 junezhang 阅读(251) 评论(0) 推荐(0) 编辑
摘要: coding=utf-8from selenium import webdriverimport timebrowser=webdrive.FireFox() #操作FireFox浏览器,新建实例browser.get('http://www.baidu.com') #打开URL用get()函数time.sleep(1) #休眠1sprint driver.title #打印页面titlebrowser.find_element_by_id('kw').send_keys('selenium') #百度输入框id='kw',依据b 阅读全文
posted @ 2014-04-07 13:00 junezhang 阅读(413) 评论(0) 推荐(0) 编辑
摘要: import xlrddata=xlrd.open_workbook('TSMdata.xlsx') #Excel文档存储路径:C:\Python27table=data.sheets()[0] #按索引获取sheetnrows=table.nrows #行数ncols=table.ncols #列数colnameindex=0 colnames=table.row_values(colnameindex) #首行列名写入数组list=[] #存放结果的数组for rownum in range(1,nrows): row=table.row_values(rownum) #循 阅读全文
posted @ 2014-04-03 10:12 junezhang 阅读(1393) 评论(0) 推荐(0) 编辑
摘要: import reimport cookielibimport urllibimport urllib2def printDelimiter(): #打印分割线 print '-'*80printDelimiter()print '[preparation] using cookiejar & HTTPCookieProcessor to antomatically handle cookies'cj=cookielib.CookieJar() #新建CookieJaropener=urllib2.build_opener(urllib2.HTTPCoo 阅读全文
posted @ 2014-03-26 06:33 junezhang 阅读(678) 评论(0) 推荐(0) 编辑
摘要: https://passport.baidu.com/v2/api/?login,Post请求该URL的包体数据分析staticpage=http%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fv3Jump.html #编码后的URL,原URL:http://www.baidu.com/cache/user/html/v3Jump.htmlcharset=utf-8 #网页编码方式token=the+fisrt+two+args+should+be+string+type%3A0%2C1%21 #动态值,需要进一步具体分析其来源tpl=mn #未知 阅读全文
posted @ 2014-03-24 16:38 junezhang 阅读(1359) 评论(1) 推荐(0) 编辑
摘要: import urllibencodedUrl='http%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fv3Jump.html' #登录百度首页抓取到的一条Post数据为编码后的URLdecodedUrl=urllib.unquote(encodedUrl) #URL解码实现:urllib.unquote()print encodedUrlprint decodedUrl 阅读全文
posted @ 2014-03-24 10:48 junezhang 阅读(228) 评论(0) 推荐(0) 编辑
摘要: import reimport cookielibimport urllibimport urllib2import optparsedef checkAllCookiesExist(cookieNameList,cookieJar): cookiesDict={} for eachCookieName in cookieNameList: cookiesDict[eachCookieName]=False allCookieFound=True for cookie in cookieJar: if(cookie.name in cookiesDict): cookiesDict[cooki 阅读全文
posted @ 2014-03-23 17:59 junezhang 阅读(589) 评论(0) 推荐(0) 编辑