本文整理汇总了Python中ghost.Ghost.fill方法的典型用法代码示例。如果您正苦于以下问题:Python Ghost.fill方法的具体用法?Python Ghost.fill怎么用?Python Ghost.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ghost.Ghost
的用法示例。
在下文中一共展示了Ghost.fill方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IDirectBroker
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
class IDirectBroker(object):
IDIRECTURL = 'https://secure.icicidirect.com/Trading/LBS/Logon.asp'
def __init__(self,username, password, **kwargs):
self.username = username
self.password = password
self.ghost = Ghost()
try:
self.page, self.resources = self.ghost.open(self.IDIRECTURL)
self.ghost.wait_for_page_loaded()
self.ghost.capture_to("./l1.png")
result, resources = self.ghost.fill("form", { "FML_USR_ID": "MUSE9L71", "FML_USR_USR_PSSWRD": "[email protected]","FML_USR_DT_BRTH":"22101982" })
self.ghost.capture_to("./l2.png")
self.page, self.resources = self.ghost.fire("form", "submit", expect_loading=True)
#self.ghost.wait_for_page_loaded()
self.ghost.capture_to("./l3.png")
except Exception,e:
raise e
示例2: __init__
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
class KuKlueCrawler:
# Class 생성자, id, pw로 KuKlue 로그인 시도
def __init__(self, id, pw, displayFlag = False, download_images=False, prevent_download=["css"]):
# 새 Ghost instance를 만들어서 사용합니다.
self.ghost = Ghost(display = displayFlag, wait_timeout = 60)
self.currentPage = None
self.login(id, pw)
# Class 소멸자
def __del__(self):
self.ghost.exit()
del self.ghost
# 요청한 url 접속
def openPage(self, url):
page, resource = self.ghost.open(url)
self.ghost.wait_for_page_loaded()
self.currentPage = url
return page, resource
# Login 하는 함수
def login(self, id, pw):
page, resource = self.openPage('http://klue.kr/')
self.ghost.evaluate("""
(function() {
document.getElementById('mb_id').value = '%s';
document.getElementById('mb_pw').value = '%s';
document.getElementsByClassName('login')[0].click();
})();
""" % (id, pw), expect_loading = True)
return page, resource
# 특정 index에 대해 lecture page 접속
def main_search(self, query=None, lectureNum=-1):
if query is not None:
self.ghost.wait_for_selector('#topBar_search')
self.ghost.fill("#sform", { "query": query })
page, resource = self.ghost.fire_on('#sform', 'submit', expect_loading = True)
if lectureNum != -1:
page, resource = self.openPage('http://klue.kr/lecture.php?no='+str(lectureNum))
return page, resource
示例3: heroku
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
def heroku(api_key, year, month):
ghost = None
file_path = '/tmp/heroku_invoice_%d-%d.png' % (year, month)
if os.path.exists(file_path):
os.remove(file_path)
# TODO: make dimensions configurable? Automatic (is that possible?)?
ghost = Ghost(viewport_size=(1000, 1600))
ghost.wait_timeout = 20
ghost.open('https://id.heroku.com/login')
ghost.fill("form", dict(email="", password=api_key))
ghost.fire_on("form", "submit", expect_loading=True)
ghost.open('https://dashboard.heroku.com/invoices/%s/%s' % (year, month))
ghost.capture_to(file_path)
return file_path
示例4: GAGetter
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
class GAGetter(object):
def __init__(self, email, password):
self.email = email
self.password = password
self.ghost = Ghost(wait_timeout=20)
def test(self):
self.sign_in()
self.go_to_realtime_site()
sleep(10)
print 'COUNTER: {0}'.format(self.get_counter())
def sign_in(self):
page, resources = self.ghost.open(
'http://www.google.com/analytics/index.html')
self.ghost.wait_for_text('Analytics')
self.ghost.wait_for_selector('a.secondary-button')
self.ghost.click('a.secondary-button')
self.ghost.wait_for_text("Can't access your account?")
self._fill_signin_form()
self.ghost.wait_for_text('All Accounts')
def _fill_signin_form(self):
result, resources = self.ghost.fill(
"form", {
"Email": self.email,
"Passwd": self.password
}
)
page, resources = self.ghost.fire_on(
"form", "submit", expect_loading=True)
self.ghost.wait_for_page_loaded()
def go_to_realtime_site(self):
m = re.search(
r"#report/visitors-overview/([a-z0-9]+)/",
self.ghost.content
)
self.ghost.evaluate(
"window.location.href = '#realtime/rt-overview/{0}/'".format(
m.group(1)
)
)
self.ghost.wait_for_text('Right now')
return self.ghost.content
def get_counter(self):
d = pq(self.ghost.content)
return d('#ID-overviewCounterValue').html()
示例5: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
#!/usr/bin/python
from ghost import Ghost
import argparse
# ghost nicely wraps a headless, WebKit browser, and loads pages that require javascript
ghost = Ghost()
ghost.open('http://duckduckgo.com/')
ghost.wait_for_selector('input[name=q]')
ghost.fill("#search_form_homepage", {'q': 'beer'})
ghost.fire_on("#search_form_homepage",
"submit",
expect_loading=True)
ghost.wait_for_selector('#r1-0')
result, _resources = ghost.evaluate(
"document.getElementById('r1-0').innerHTML;")
print result
示例6: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
import secrets
import time
from ghost import Ghost
ghost = Ghost()
page, resources = ghost.open('https://my.ecofactor.com/mobile/login.html')
result, resources = ghost.fill('form', {
'j_username': secrets.username,
'j_password': secrets.password
})
page, resources = ghost.fire_on('form', 'submit')
#page, resources = ghost.fire_on('form', 'submit', expect_loading=True)
page, resources = ghost.wait_for_page_loaded()
ghost.capture_to("/tmp/foo.png")
print page.http_status
#print resources
示例7: RunExport
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
def RunExport():
ghost = Ghost(viewport_size=(1200, 2400), display=False, wait_timeout=30, cache_dir=CACHE_DIRECTORY)#, log_level=logging.ERROR
#
#login_password
#submit.x
#submit
page, resources = ghost.open('https://www.paypal.com/ie/cgi-bin/webscr?cmd=_login-run')
result, resources = ghost.fill("form[name=login_form]", {
"login_email": PAYPAL_USERNAME,
"login_password": PAYPAL_PASSWORD
})
page, resources = ghost.fire_on("form[name=login_form]", "submit", expect_loading=True)
result, resources = ghost.wait_for_page_loaded()
#wait for 10 seconds
#time.sleep(10)
page, resources = ghost.open('https://www.paypal.com/ie/cgi-bin/webscr?cmd=_account')
result, resources = ghost.wait_for_text("Welcome, %s" % PAYPAL_NAME)
getHistoryListing(ghost)
first_run = True
#get the next url
#print ghost.evaluate('document.querySelectorAll("#tableWrapperID .pagination:nth-child(1) a.btnLink");')[0]
nav_links_eval = """
var links = document.querySelectorAll(".pagination a.btnLink");
links.length;
"""
nav_links = ghost.evaluate(nav_links_eval)
page_count = START_AT_PAGE
transaction_count = 0
if page_count > 0:
transaction_count = page_count * 20
goToPage(ghost,page_count)
#transaction_list_url = resources[0].url
#print transaction_list_url
while nav_links[0] > 0 or first_run==True:
first_run = False
page_count = page_count + 1
filteredlisting_export = os.path.join(EXPORT_DIRECTORY,'filteredhistory%d.png' % page_count)
if not os.path.isfile(filteredlisting_export):
ghost.capture_to(filteredlisting_export, selector="body")
transaction_urls = ghost.evaluate("""
var links = document.querySelectorAll("#transactionTable tr.primary td.detailsNoPrint a");
var listRet = [];
for (var i=0; i<links.length; i++){
listRet.push(links[i].href);
}
listRet;
""")
for transaction_href in transaction_urls[0]:
transaction_count = transaction_count + 1
#print urllib.unquote(transaction_href)
page, resources = ghost.open(urllib.unquote(transaction_href))
ghost.wait_for_page_loaded()
payee_name = None
date_string = None
date = ghost.evaluate("""
document.querySelectorAll("#historyMiniLog tbody tr")[2].querySelectorAll('td')[0].innerHTML;
""")
if date and date[0]:
date_string = date[0].replace(' ','')
payee = ghost.evaluate("""
document.querySelectorAll("#historyMiniLog tbody tr")[2].querySelectorAll('td')[1].innerHTML;
""")
if payee and payee[0]:
payee_name = safeFilename(payee[0].replace(' ',''))
if payee_name and date_string:
date_object = datetime.strptime(date_string, '%d-%b-%Y')
date_string=datetime.strftime(date_object,'%Y-%m-%d')
print 'page %d transaction %d [%s - %s]' % (page_count, transaction_count, date_string, payee_name)
purchasedetails_export = os.path.join(EXPORT_DIRECTORY,'%s_%s_%s.png' % (date_string,payee_name,transaction_count ))
if not os.path.isfile(purchasedetails_export):
print '\t\tsaving to %s' % purchasedetails_export
ghost.capture_to(purchasedetails_export, selector="#xptContentMain")
else:
print '\t\tAlready saved to %s' % purchasedetails_export
else:
purchasedetails_export = os.path.join(EXPORT_DIRECTORY,'no date and payee - page-%d_ transaction %d.png' % (page_count,transaction_count ))
print '\t\tsaving to %s' % purchasedetails_export
if not os.path.isfile(purchasedetails_export):
#.........这里部分代码省略.........
示例8:
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
if (len(sys.argv) == 4):
URL = "http://172.16.0.1"
ADMIN_USER = "admin"
admin_password = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
page, extra_resources = ghost.open(URL)
# At the login page?
if page.http_status==200:
# Fill out login form
result, resources = ghost.fill("form[name=login_iform]", {
"usernamefld": ADMIN_USER,
"passwordfld": admin_password
})
# Trigger click on submit button using it's CSS class as selector.
# Simply submitting the form does not work because of their JS implementation.
page, resources = ghost.fire_on(".formbtn", "click", expect_loading=True)
if page.http_status == 200:
# Make sure we are logged in.
result, resources = ghost.wait_for_selector("title")
if "moat.ym - Status: Dashboard" in ghost.content:
# Let's go to the VPN add user page
ghost.open(URL + "/vpn_pptp_users_edit.php")
result, resources = ghost.wait_for_selector("title")
示例9: type
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
# -*- coding:utf-8 -*-
from ghost import Ghost
from toString import toString
import codecs
import time
ghost=Ghost(wait_timeout=60)
page,resources=ghost.open('http://login.benshouji.com/')
ghost.wait_for_page_loaded()
result, resources = ghost.fill("form", {"uname": "0a1rzbqwjfhg85","pwd": "123456789"})
page,resources=ghost.click("#loginbtn", expect_loading=True)
print 'login succeed'
page,resources=ghost.open('http://fahao.benshouji.com/holiday/5605004484/')
ghost.wait_for_page_loaded()
#ghost.click('#linghao')
result, resources=ghost.evaluate('document.getElementById("linghao").click();')
#ghost.fill('')
result,resources=ghost.evaluate('document,getElementById("")')
time.sleep(30)
print result
print resources
print type(ghost.cookies)
fp=codecs.open('test.html','w','utf-8')
fp.write(ghost.content)
#print ghost.content
示例10: type
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
url = 'http://www.yamaha-motor.com.tw/dealer/dealer.aspx'
mapUrl = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&language=zh-tw&address='
ghost.open(url)
html = ghost.content.encode('utf-8');
#print type(html.encode('utf8'))
page = etree.HTML(html)
cityOption = page.xpath(u"//select[@id='ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_selCity']")[0]
cities = cityOption.xpath("./option/@value")
shopList = []
f2 = open('yamaha_location2.txt','a')
for city in cities:
if city != '':
print city
result, resources = ghost.fill("#aspnetForm", {
"ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$selCity": city,
"sss": "1"
})
ghost.fire_on("#aspnetForm", "submit", expect_loading=True)
html = ghost.content.encode('utf-8');
page = etree.HTML(html)
dealer = page.xpath(u"//table[@id='dealerTD1']")[0]
for shop in dealer.xpath('./tbody/tr'):
name = shop.xpath('./td[1]/a/text()')[0].encode('utf8').strip()
address = shop.xpath('./td[2]/text()')[0].encode('utf8').strip()
response = urllib2.urlopen(mapUrl + address)
responseJSON = response.read()
jsonObj = json.loads(responseJSON)
loc = jsonObj['results'][0]['geometry']['location']
location = str(loc['lat']) + ';' + str(loc['lng'])
print location
phone = shop.xpath('./td[3]/text()')[0].encode('utf8').strip()
示例11: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
from ghost import Ghost
from local import settings
ghost = Ghost()
page, resources = ghost.open('http://www.economist.com/audio-edition/latest')
result, resources = ghost.fill("#user-login", {
"name": settings['email_address'],
"pass": settings['password']
})
print 'logging in'
page, resources = ghost.fire_on("#user-login", "submit", expect_loading=True)
download_url, resources = ghost.evaluate(
"document.querySelector('.audio-issue-full-download-link > a').getAttribute('href');")
print 'download url {}'.format(download_url)
示例12: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
Usage:
python django_admin_login.py <username> <password>
(where the username and password are entered into the corresponding boxes)
"""
import sys
from ghost import Ghost
import Image
username = sys.argv[1]
password = sys.argv[2]
django_admin_url = "http://127.0.0.1:8000/admin/"
image_file = "django_admin_login.png"
ghost = Ghost()
page, extra_resources = ghost.open(django_admin_url)
ghost.wait_for_selector('#id_username')
ghost.wait_for_selector('#id_password')
ghost.fill("#login-form", {'username': username, 'password': password})
ghost.capture_to(image_file, zoom_factor=3.0)
print "Captured django_admin_login.png"
# Crop bad space at the top due to the odd page layout
im = Image.open(image_file)
box = (0, 300, 1014, 1062)
region = im.crop(box)
region.save(image_file)
示例13: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import fill [as 别名]
if not args.image:
args.image = 'image.jpg'
urllib.urlretrieve(default_img_url, args.image)
podcast['image'] = args.image
ghost = Ghost(wait_timeout=timeout)
# Получаем страницу с формой логина
page, resources = ghost.open(add_page)
assert page.http_status == 200 and 'loginForm' in ghost.content
# Заполняем форму логина
ghost.fill('#loginForm',
{
'login': user,
'password': passwd
}
)
page, resources = ghost.fire_on('#loginForm',
'submit',
expect_loading=True)
assert page.http_status == 200 and u'Выход' in ghost.content
# Получаем страницу с формой добавления файла
page, resources = ghost.open(add_page)
assert page.http_status == 200 and 'formulaire' in ghost.content
# Заполняем форму добавления файла
ghost.fill('#formulaire', {'file': args.file})
page, resources = ghost.fire_on('#formulaire',
'submit',