本文整理汇总了Python中splinter.Browser.is_element_not_present_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.is_element_not_present_by_id方法的具体用法?Python Browser.is_element_not_present_by_id怎么用?Python Browser.is_element_not_present_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splinter.Browser
的用法示例。
在下文中一共展示了Browser.is_element_not_present_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DownPatent
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_id [as 别名]
class DownPatent(object):
def __init__(self, db, down_url):
self.db = db
self.down_url = down_url
self.browser = Browser("phantomjs", wait_time=10)
#self.browser = Browser()
#下载专利
def download(self, patentno):
#访问网页
#网页加载超时
#down_flag, 0:未下载,1:不存在,2:下载失败
download_link = ""
down_flag = 0
if True:
print "打开网页"
self.browser.visit(self.down_url)
if not self.browser.is_element_not_present_by_value("查询", wait_time=10):
#填写专利号
self.browser.fill("cnpatentno", patentno)
self.browser.find_by_value("查询").first.click()
print "填写专利号"
#连接超时,404
if self.browser:
print "打开验证码网页"
#一个最多循环20次
code_handler = CodeHandler()
#填写验证码
list_fill_text = []
#验证码路径
list_code_path = []
#验证码分割标志
list_split_flag = []
#验证码识别标志
list_reg_flag = []
for code_num in xrange(20):
print code_num
#查找验证码
if not self.browser.is_element_not_present_by_id("getcode", wait_time=5):
print "查找验证码"
#截图
#self.browser.driver.maximize_window()
self.browser.driver.save_screenshot("screenshot.png")
#获取验证码图片
image = Image.open("screenshot.png")
image_location = self.find_location(image)
image_code = image.crop((image_location[0], image_location[1], image_location[0]+52, image_location[1]+21))
save_path = "static/images/onlinecode/" + time.ctime() + ".png"
save_path_temp = "../%s" % save_path
image_code.save(save_path_temp)
list_code_path.append(save_path)
#分割图片
list_split_image = self.deal_split(code_handler, image_code)
#识别,如果能正确识别,则识别,不能,则重新获取验证码
if len(list_split_image) == 4:
print "正确分割"
list_split_flag.append(1)
reg_plain_text = self.reg_code(list_split_image)
fill_text = "".join(reg_plain_text)
list_fill_text.append(fill_text)
#填写验证码
#hand_fill_text = raw_input("Enter fill text:")
self.browser.fill("ValidCode", fill_text)
self.browser.find_by_value("确定").first.click()
print self.browser.html.encode("utf-8").find("验证码输入错误")
if self.browser.html.encode("utf-8").find("验证码输入错误") == -1:
list_reg_flag.append(1)
if self.browser.html.encode("utf-8").find("没有找到该专利") == -1:
down_link_one = self.browser.find_link_by_text("申请公开说明书图形下载(标准版)")
down_link_two = self.browser.find_link_by_text("申请公开说明书图形下载(极速版)")
if down_link_one or down_link_two:
print "查找说明书图形下载链接"
list_reg_flag.append(1)
if down_link_one:
self.browser.click_link_by_text("申请公开说明书图形下载(标准版)")
else:
self.browser.click_link_by_text("申请公开说明书图形下载(极速版)")
print "查找下载链接"
#查找下载链接
download_a = self.browser.find_link_by_text("下载专利")
if download_a:
download_link = download_a["href"]
#找到下载链接
down_flag = 3
break
else:
print "下载失败"
#下载失败
down_flag = 2
break
'''
else:
print "识别正确,未找到链接"
list_reg_flag.append(0)
self.browser.back()
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_id [as 别名]
#.........这里部分代码省略.........
link.click()
break
self.browser.fill('departure:dateField', task.date)
if date_return:
self.browser.fill('returnDeparture:dateField', date_return)
if is_open:
self.browser.check('returnTicketOpen')
self.browser.find_option_by_text('ISIC').first.check()
self.browser.find_by_value('Vyhledat').first.click()
while self.browser.is_element_not_present_by_css('.left_column',
wait_time=1):
pass
items = self.browser.find_by_css('.left_column') \
.find_by_xpath('div/div/*')
connections = []
for item in items:
if item.tag_name == 'h2':
date_local = item.text.split(' ')[1]
elif item.tag_name == 'div' and item.has_class('routeSummary'):
assert date_local
if date_local != task.date:
break
connections.append(Connection(item))
return connections
def order_time(self, connection):
while True:
if connection.click():
self.browser
dialog = self.browser.find_by_css('[id^=_wicket_window]')
if dialog:
dialog.first.find_by_tag('button').click()
if self.browser.is_element_present_by_id('sumary_lines',
wait_time=1):
break
self.browser.find_by_id('sumary_lines') \
.first.find_by_tag('button') \
.first.click()
seats = {}
bus = self.browser.find_by_css('.seatsContainer')
if bus:
for seat in bus.first.find_by_css(
'.seatContainer:not([style*=blocked])'):
seats[int(seat.find_by_tag('div').first.html[:-1])] = seat
else:
bus = self.browser.find_by_css('.vehicle')
for seat in bus.first.find_by_css('.free, .selected'):
seats[int(seat.text[:-1])] = seat
return seats
def order_seat(self, seat):
if not seat.has_class('selected'):
seat.click()
for fs in self.browser.find_by_css('fieldset.topRoute'):
legend = fs.find_by_css('legend')
if legend and 'Pojištění' in legend[0].text:
for package in fs.find_by_css('.insurancePackageType'):
if 'nechci' in package.find_by_tag('label').text:
package.find_by_tag('input').click()
time.sleep(1)
submit = self.browser.find_by_css('[name^=buttonContainer]').first
interaction_type = submit.text
reserved = 'Rezervovat' in interaction_type
if not reserved:
submit.click()
time.sleep(1)
data = (self.user['first'],
self.user['last'],
self.user['email'],
self.user['phone'])
for item, value in zip(self.browser.find_by_id('passengerInfo')
.first.find_by_tag('input'),
data):
item.fill(value)
submit = self.browser.find_by_css('[name^=buttonContainer]').first
interaction_type = submit.text
assert 'Rezervovat' in interaction_type
agreement = self.browser.find_by_css('[name="bottomComponent:termsAgreementCont:termsAgreementCB"]')
if agreement:
agreement[0].check()
time.sleep(1)
submit.click()
with open('conf.yaml') as f:
conf = yaml.load(f)
if 'email' in conf:
email = conf['email']
while self.browser.is_element_not_present_by_id('ticketPage', wait_time=1):
pass
msg = MIMEText(self.browser.find_by_id('ticketPage').first.html, 'html')
msg['Subject'] = 'SA reservation'
msg['From'] = email['from']
msg['To'] = self.user['email']
username = email['username']
password = email['password']
server = smtplib.SMTP(email['server'])
server.starttls()
server.login(username, b64decode(password).decode())
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
示例3: sleep
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_id [as 别名]
# -*-coding:utf-8-*-
#! usr/bin/python
#小学期截课脚本
__author__='Zheng Wu'
from time import sleep
from splinter import Browser
browser=Browser('chrome')
url='http://electsys.sjtu.edu.cn/edu/login.aspx'
browser.visit(url)
sleep(30)
browser.visit('http://electsys.sjtu.edu.cn/edu/student/elect/warning.aspx?xklc=2&lb=3')
button=browser.find_by_id('CheckBox1')
if (browser.is_element_not_present_by_id('CheckBox1')):
pass
else:
button.click()
browser.find_by_id('btnContinue').click()
while 1:
browser.find_by_value('AD001').click() #value为对应的课程代码
browser.find_by_id('lessonArrange').click()
browser.find_by_name('myradiogroup').click()
browser.find_by_id('LessonTime1_btnChoose').click()
if browser.is_element_not_present_by_id('Button1'):
browser.find_by_id('btnSubmit').click()
print 'successfully get class!'
browser.quit()
else:
示例4: WorkerThread
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_id [as 别名]
#.........这里部分代码省略.........
+ "\n"
+ meal_mapping[meal]
+ u" روز "
+ day_mapping[selected_day]
+ u" هیچ یک از انتخاب های شما سرو نمی شود ",
)
meal += 1
else:
self.emit(
SIGNAL("log(QString)"),
self.username
+ ":"
+ "\n"
+ u" همه ی وعده های روز "
+ day_mapping[selected_day]
+ u" قبلا رزرو شده یا سلف تعطیل است ",
)
def decode_database(self, name_of_database):
json_file = open("./foodlists/" + name_of_database, "r")
json_decoded = json.load(json_file)
foods = json_decoded["foods"] # export foods
rests_and_day_numbers_of_week = json_decoded["restsOfEachDay"] # export days
user_list_version = json_decoded["version"]
return (foods, rests_and_day_numbers_of_week, user_list_version)
def login(self, username, password):
self.browser = Browser("phantomjs")
self.browser.driver.set_window_size(800, 371)
self.wait_time = 2
self.browser.visit("http://sups.shirazu.ac.ir/sfxweb/Gate/Login.aspx")
self.browser.is_element_not_present_by_id("edId", self.wait_time) # wait until see the element
self.browser.find_by_id("edId").fill(username)
self.browser.find_by_id("edPass").fill(password)
self.browser.find_by_id("edWebApp").select(1)
self.browser.find_by_id("edEnter").click()
self.browser.find_by_css("ul.active:nth-child(3) > li:nth-child(2)").click()
def reserve_this(self, selected_date, selected_rest, selected_meal, foods_of_meal):
# select restaurant
rest = self.browser.find_by_id("edRestaurant")
self.browser.select("edRestaurant", selected_rest)
# select date
self.browser.is_element_not_present_by_id("edDate", self.wait_time) # wait until see the element
self.browser.select("edDate", selected_date)
# select meal
self.browser.is_element_not_present_by_id("edMeal", self.wait_time) # wait until see the element
meal = self.browser.find_by_id("edMeal")
meal.select(selected_meal)
# collect serving foods
serving_foods = []
self.browser.is_element_not_present_by_id("Food", self.wait_time) # wait until see the element
number_of_foods = len(self.browser.find_by_css("#Food li"))
for nth in range(1, number_of_foods + 1):
value = self.browser.find_by_css("#Food > li:nth-child(" + str(nth) + ") > input:nth-child(1)").value
serving_foods.append(value)
# select food and reserv
reserved = False
for food in foods_of_meal: # select food of that meal
if str(food) in serving_foods:
示例5: build_grades
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_id [as 别名]
try:
b.visit(MINERVA_HOME)
b.find_by_id('mcg_un').fill(credentials[0])
b.find_by_id('mcg_pw').fill(credentials[1])
b.find_by_id('mcg_un_submit').click()
b.visit(MINERVA_TRANSCRIPT)
grades = build_grades()
b.visit(MINERVA_LOGOUT)
while True:
time.sleep(DELAY)
b.visit(MINERVA_HOME)
if b.is_element_not_present_by_id('mcg_un'):
log.warning('Minerva home missing login, trying again in %d seconds' % DELAY)
continue
b.find_by_id('mcg_un').fill(credentials[0])
b.find_by_id('mcg_pw').fill(credentials[1])
b.find_by_id('mcg_un_submit').click()
b.visit(MINERVA_TRANSCRIPT)
compare_grades(grades)
log.info('Update complete')
b.visit(MINERVA_LOGOUT)
except Exception:
ex_type, ex, tb = sys.exc_info()
traces = traceback.format_list(traceback.extract_tb(tb))
message = ''
for t in traces:
示例6: sleep
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_not_present_by_id [as 别名]
#查找小学期海选时所有的课程的平均分及最高分
__author__='Zheng Wu'
from time import sleep
from splinter import Browser
import re
browser=Browser('chrome')
url='http://electsys.sjtu.edu.cn/edu/login.aspx'
browser.visit(url)
print u'你现在有20s的时间输入jaccount'
sleep(15)
print u'请稍等,本程序稍微有点慢.在这段等待的时间,你可以先打开你的微信^_^'
browser.visit('http://electsys.sjtu.edu.cn/edu/student/elect/warning.aspx?xklc=1&lb=3')
button=browser.find_by_id('CheckBox1')
if (browser.is_element_not_present_by_id('CheckBox1')):
pass
else:
button.click()
browser.find_by_id('btnContinue').click()
#获取所有课程编码
pattern=re.compile(r'[A-Z]{2}[0-9]{3}')
classlist=[]
for ele in browser.find_by_tag('td'):
if (re.match(pattern,ele.text)):
classlist.append(ele.text)
#打开微信
wechaturl='http://wechat.shwilling.com/auth/qrcode/login?redirect=http%3A%2F%2Fwechat.shwilling.com%2Fsjtu%2Fcourse'
browser.visit(wechaturl)