当前位置: 首页>>代码示例>>Python>>正文


Python Ghost.set_field_value方法代码示例

本文整理汇总了Python中ghost.Ghost.set_field_value方法的典型用法代码示例。如果您正苦于以下问题:Python Ghost.set_field_value方法的具体用法?Python Ghost.set_field_value怎么用?Python Ghost.set_field_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ghost.Ghost的用法示例。


在下文中一共展示了Ghost.set_field_value方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_excede_html

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import set_field_value [as 别名]
def get_excede_html():
	result = 'unknown'
	usage_page_html = ''
	username, password = load_auth_info()
	#print "ghost initialized..."
	ghost = Ghost(wait_timeout=50, log_level='DEBUG', download_images=False)
	
	#Check for FAIL: no internet access
	try:
		page,resources = ghost.open('https://my.exede.net/usage')
	except Exception as e:
		print e.message
		result = e.message
		ghost.exit()
		return usage_page_html, result

	ghost.wait_for_page_loaded()

	if ghost.exists(".form-control.input-lg.required[name=IDToken1]"):
		print "Login found"
	else:
		print "Login not found"
		result = 'Can\'t find login box on website'
		ghost.exit()
		return usage_page_html, result

	print "Filling in field values"
	ghost.set_field_value(".form-control.input-lg.required[name=IDToken1]",username)
	ghost.set_field_value(".form-control.input-lg.required[name=IDToken2]",password)
	print "Clicking form button"
	ghost.click('.btn.btn-info.btn-lg.pull-right.col-lg-4[name="Login.Submit"]')
	print "Waiting for page to load"
	ghost.wait_for_page_loaded()

	try:
		if ghost.wait_for_selector('.amount-used',timeout=60):
			print "Found the amount used..."
			result = 'OK'
		else:
			print "Did not find the amount used"	
			result = 'OK'
			#ghost.exit()
			#return usage_page_html, result

	except Exception as e:
		print e.message
		result = e.message

	
	usage_page_html = ghost.content.encode('ascii', 'ignore')
	
	print "Writing resulting page to disk as final_page.html"
	with open('final_page.html', 'w') as data_file:
		data_file.write(usage_page_html)
	
	ghost.exit()
	return usage_page_html, result
开发者ID:vipperofvip,项目名称:skymeter,代码行数:59,代码来源:exede.py

示例2: len

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import set_field_value [as 别名]
if len(sys.argv) != 4:
	print 'Params: username password placename'
	exit(2)
else:
	username = sys.argv[1]
	password = sys.argv[2]
	placename = sys.argv[3]


print "Status: 1"

page, resources = ghost.open('https://foursquare.com/mobile/login?continue=%2Fmobile%2F')
ghost.wait_for_page_loaded()

print "Status: 2"
result, resources = ghost.set_field_value("input[name=username]", username)
result, resources = ghost.set_field_value("input[name=password]", password)
page, resources = ghost.fire_on("form", "submit", expect_loading=True)
ghost.wait_for_page_loaded()


print "Status: 3"
page, resources = ghost.open('https://foursquare.com/mobile/checkin')
ghost.wait_for_page_loaded()


print "Status: 4"
result, resources = ghost.set_field_value("input[name=q]", placename)
page, resources = ghost.fire_on("form", "submit", expect_loading=True)
ghost.wait_for_page_loaded()
开发者ID:jooray,项目名称:foursquare_checkin,代码行数:32,代码来源:foursquare.py

示例3: Crawler

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import set_field_value [as 别名]

#.........这里部分代码省略.........
                print e['onclick'], 'no page loaded'
            except:
                print traceback.format_exc()
        self.ghost.wait_timeout = page_timeout

        #获取超链接
        array = soup.find_all('a')
        for a in array:
            try:
                continue_flag = 0
                url = standard(target_url, a['href'])
                for k in ['javascript:;', 'return false;', 'logout']:
                    if url.lower().find(k) != -1:
                        continue_flag = 1
                        break
                if continue_flag == 1:
                    continue
                if url.startswith('http'):
                    self.__add_url(all_url, url) #url
                elif url not in url_queue and not url.startswith('#'):
                    url_queue.append(url)
                    self.ghost.click(\'''a[href="%s"]\''' % url, expect_loading=True)
                    url, resources = self.ghost.evaluate('window.location.href')
                    if url != target_url:
                        self.__add_url(all_url, str(url))
                        self.ghost.open(target_url)
            except TimeoutError:
                print url, 'failed'
            except KeyError:
                pass
            except:
                print url, traceback.format_exc()
        '''
        #获取表单
        target_forms = []
        forms = soup.find_all('form')
        for input, form in enumerate(forms):
            names = []
            inputs = form.find_all('input', type=lambda type: type == 'text' or type == 'password'or not type)
            texts = form.find_all('textarea')
            for input in inputs:
                try:
                    names.append(input['name'])
                except KeyError:
                    pass
            for text in texts:
                try:
                    names.append(text['name'])
                except KeyError:
                    pass
            if len(names) > 0:
                target_forms.append((input, sorted(names)))
        print 'target', target_forms
        for input, names in target_forms:
            self.submit_xss(all_url, target_url, input, names) #表单序号及其所有输入框
            #深度优先
        for url in all_url:
            self.__page_crawler(url, depth + 1)

    def __del__(self):
        self.ghost.exit()

    def submit_xss(self, all_url, target_url, form_i, names):
        for input, xss in enumerate(xss_rsnake):
            print 'submit', names, xss
            try:
                if input > 0:
                    self.ghost.open(target_url)
                for name in names:
                    try:
                        self.ghost.evaluate(
                            "document.querySelectorAll('*[name=%s]')[0].removeAttribute('onfocus');" % name)
                        #填写表单
                        self.ghost.set_field_value("*[name=%s]" % name, xss)
                    except:
                        print traceback.format_exc()
                self.ghost.evaluate(
                    "document.querySelectorAll('input[type=submit]')[0].removeAttribute('onclick');")

                #提交表单 自动
                self.ghost.click('input[type=submit]')#, expect_loading=True)
                #self.ghost.evaluate(
                 #   "document.querySelectorAll('form')[%d]['submit']();" % form_i)#, expect_loading=True)

                try:
                    self.ghost.wait_timeout = alert_timeout
                    result, resources = self.ghost.wait_for_alert()
                    print '============================================================'
                    print 'alert:', result
                    print '============================================================'
                    if result == 'XSS':
                        break
                except TimeoutError:
                    pass
                finally:
                    self.ghost.wait_timeout = page_timeout
                    url, resources = self.ghost.evaluate('window.location.href')
                    self.__add_url(all_url, str(url))
            except TimeoutError:
                print 'failed'
开发者ID:surpassly,项目名称:front,代码行数:104,代码来源:backup.py

示例4: getdata

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import set_field_value [as 别名]
def getdata():
    countnumber = 0
    correctnumber = 0
    global finalnumber, standhash
    for i in range(0, 10):
        standhash[i] = get_hash(Image.open(os.path.join(os.path.dirname(__file__), '../static/img/yzm/stand').replace('\\', '/') + str(i) + ".png"))
    for j in range(0, 1):
        ghost = Ghost()
        page, resources = ghost.open('http://202.112.132.147:7001/ieas2')
        page, resources = ghost.evaluate(
        '''function getBase64Image(img) {
        // Create an empty canvas element
        var canvas = document.createElement("canvas");
        canvas.width = img.width;
        canvas.height = img.height;

        // Copy the image contents to the canvas
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img, 0, 0);

        // Get the data-URL formatted image
        // Firefox supports PNG and JPEG. You could check img.src to
        // guess the original format, but be aware the using "image/jpg"
        // will re-encode the image.
        var dataURL = canvas.toDataURL("image/png");

        return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
    }
    getBase64Image(document.getElementById('yzmmsg'));
    ''')
        img1 = Image.open(BytesIO(base64.b64decode(page)))
        #img1 = Image.open("/Users/selfdir/Documents/calgpa/static/img/wrong0.626485832093.png")
        pointx = 10
        for i in range(0, 4):
            (gap, thenumber) = tryit(img1, pointx)
            finalnumber += str(thenumber)
            if thenumber == 1:
                pointx = pointx + gap + 8
            else:
                pointx = pointx + gap + 9
        #print finalnumber
        result, resources = ghost.set_field_value("input[id=username]", sys.argv[1])
        result, resources = ghost.set_field_value("input[id=password]", sys.argv[2])
        result, resources = ghost.set_field_value("input[id=code]", finalnumber)
        #ghost.capture_to('/Users/selfdir/Documents/calgpa/static/img/xxxx.png')
        try:
            page, resources = ghost.evaluate(
        '''login();
    ''', expect_loading=True)
            if page.url == "http://202.112.132.147:7001/ieas2/login":
                #correctnumber += 1
                for j in allyear:
                    page, resources = ghost.open('http://202.112.132.147:7001/ieas2/cj/xs_findcj?xnxqMap=' + j)
                    print page.content
                    print "woshifengexian"
        except:
            print "fuckkkkkkkkkk"
        return finalnumber
        finalnumber = ''
        countnumber += 1
        #print str(correctnumber * 100.0 / countnumber) + '%'
        ghost.exit()
开发者ID:numbbbbb,项目名称:-gpacalculator-for-buaa,代码行数:64,代码来源:getdata.py

示例5: Ghost

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import set_field_value [as 别名]
from ghost import Ghost

url = "http://www.ebay.com/"
gh = Ghost()

# We load the main page of ebay
page, resources = gh.open(url, wait_onload_event=True)

# Full the main bar and click on the search button
gh.set_field_value("#gh-ac", "plane")
gh.click("#gh-btn")

# Wait for the next page
gh.wait_for_selector("#e1-15")

# Save the image of the screen
gh.capture_to("plane.png")
开发者ID:imclab,项目名称:pylines,代码行数:19,代码来源:example.py


注:本文中的ghost.Ghost.set_field_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。