本文整理汇总了Python中splinter.Browser类的典型用法代码示例。如果您正苦于以下问题:Python Browser类的具体用法?Python Browser怎么用?Python Browser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Browser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_queue2csvzhconsumer
def test_queue2csvzhconsumer(self):
container = Queue()
consumer = QueueConsumer(container)
store = CSVStore(CSV_FILENAME, CSV_FIELDNAMES)
zhconsumer = ZHConsumer(consumer, store)
browser = Browser('firefox')
browser.visit('http://127.0.0.1:8888')
zhconsumer.start()
"""函数的启动方式
thread.start_new_thread(函数, (参数列表))
"""
data = html.document_fromstring(browser.html)
for i in range(1000):
container.put(data)
while 1:
if not container.qsize():
break
else:
print("the size of queue : %s" % str(container.qsize()))
# tmd , 不加 睡眠,那么,gil 都在 这个循环的手上了
# time.sleep(1)
zhconsumer.close()
zhconsumer.stop()
开发者ID:xujianhai,项目名称:zhihu,代码行数:31,代码来源:zhconsumerTest.py
示例2: main
def main():
try:
site_name = str(sys.argv[1])
except Exception as ex:
print('Insert URL to access site.json file')
print(ex)
sys.exit(-1)
site_name_clean = remove_bars(site_name)
req = requests.get(site_name_clean + "/site.json")
if req.status_code != 200:
print("Only OK! This response is " + req.status_code)
sys.exit(-1)
check_dir("typoshot-output")
j = json.loads(req.text)
for i in j["pages"]:
browser = Browser("firefox")
browser.visit(i["url"])
if browser.status_code.is_success():
str_replaced = i["title"].replace(" ", "-")
browser.driver.save_screenshot(str_replaced + ".png")
browser.quit()
开发者ID:flavertonrr,项目名称:typo-shot,代码行数:26,代码来源:__init__.py
示例3: searchorder
class searchorder(object):
def __init__(self,browser_type):
self.browser_type=browser_type
self.site='http://www.kuaixiuagency.com'#登录页面
def config(self,placeholder=''):
self.placeholder=placeholder
def verify(self,case):
self._fill_form()
if case==1:#.输入存的订单号可以搜索到对应的订单
if True:#显示搜索到的订单
self.browser.quit()
return u'通过'
else:
self.browser.quit()
return u'失败'
elif case==2:#输入不存在的订单不能搜索到订单
pass#没有显示该订单号
self.browser.quit()
elif case==3:#输入部分订单号可以搜索到包含该部分订单号的所有订单
pass#显示包括订单号的所有订单
self.browser.quit()
elif case==4:#不输入任何内容不能搜索到订单
pass#不显示任何内容,验证没有搜索到订单
self.browser.quit()
def _login(self):
self.browser=Browser(self.browser_type)
self.browser.visit(self.site)
def _fill_form(self):
self._login()
开发者ID:Josen15,项目名称:kuaixiuscript,代码行数:29,代码来源:test_search_order.py
示例4: run_for_browser
def run_for_browser(server, frmvars, browser, extra_params=None):
if extra_params is None:
extra_params = {}
url = server['url']
TestBase.log(1, 'BROWSER', browser)
br = Browser(browser, **extra_params)
if TestMode.remote_testdb_on(br, server):
# default tests
test_obj = TestConfiguredUsers(br, url, frmvars)
test_obj.run()
# user defined tests from modules/_plugin_splinter_tests
for TestClass in TESTCLASSES:
if frmvars['all_tests'] or frmvars.get('test_' + TestClass, False):
TestBase.log(2, 'TESTCLASS', TestClass)
test_obj = globals()[TestClass](br, url) #** see imports
test_obj.run()
# seems not necessary and not good here: TestMode.remote_testdb_off(br, server)
else:
TestBase.log(2, 'FATAL', 'Cannot log in.')
br.quit()
print
开发者ID:zvolsky,项目名称:codex2020,代码行数:27,代码来源:plugin_splinter.py
示例5: Webkit
class Webkit(object):
""
def __init__(self):
self.tag_attr = {
'*': 'href',
'frame': 'src',
'iframe': 'src',
'object': 'src'
}
def get_links(self, url):
links = []
self.browser = Browser('phantomjs')
self.browser.visit(url)
for tag, attr in self.tag_attr.viewitems():
llinks = self.browser.find_by_xpath('//%s[@%s]'% (tag, attr))
if not llinks:
continue
for link in llinks:
link = link.__getitem__(attr)
if not link:
continue
if link == 'about:blank' or link.startswith('javascript:'):
continue
if not link.startswith('http:'):
link = urlparse.urljoin(url, link)
links.append(link)
return links
def close(self):
self.browser.quit()
开发者ID:SainXIII,项目名称:DSpider,代码行数:32,代码来源:parser.py
示例6: WebKit
class WebKit(object):
'''WebKit引擎'''
def __init__(self):
self.tag_attr_dict = {'*':'href',
'embed':'src',
'frame':'src',
'iframe':'src',
'object':'data'}
def extract_links(self,url):
'''
抓取页面链接
'''
self.browser = Browser("phantomjs")
try:
self.browser.visit(url)
except Exception,e:
return
for tag,attr in self.tag_attr_dict.iteritems():
link_list = self.browser.find_by_xpath('//%s[@%s]' % (tag,attr))
if not link_list:
continue
for link in link_list:
link = link.__getitem__(attr)
if not link:
continue
link = link.strip()
if link == 'about:blank' or link.startswith('javascript:'):
continue
if not link.startswith('http'):
link = urlparse.urljoin(url,link)
yield link
开发者ID:bearsiji,项目名称:vulcan,代码行数:32,代码来源:utils.py
示例7: test_set_episode
def test_set_episode(self):
browser = Browser("firefox", extensions=["adblock.xpi"])
browser.visit("http://kinox.to/Stream/The_Big_Bang_Theory.html")
stream = script.watchSeries("http://kinox.to/Stream/The_Big_Bang_Theory.html", 100, 100, None)
stream.set_episode(browser)
sleep(5)
browser.quit()
开发者ID:pafi1,项目名称:stream,代码行数:7,代码来源:test.py
示例8: GoogleTestCase
class GoogleTestCase(unittest.TestCase):
def setUp(self):
self.browser = Browser('phantomjs')
self.browser.visit('http://google.com')
def test_check_title(self):
assert self.browser.title == 'Google'
开发者ID:josemazo,项目名称:learning-splinter-phantomjs,代码行数:7,代码来源:the_phantom.py
示例9: editcompany
class editcompany(object):
def __init__(self,browser_type):
self.browser_type=browser_type
self.browser=Browser(self.browser_type)
self.site='http://www.kuaixiuagency.com'#登录页面
self.browser.visit(self.site)
def config(self,name='',type=''):
self.name=name
self.type=type
def verify(self,case):
pass
if case==1:#正确更改公司有关内容可以编辑成功
pass
if True:#验证公司名称和类型是否和输入一致
self.browser.quit()
return u'通过'
else:
self.browser.quit()
return u'失败'
elif case==2:#删除公司名称,选择其他类型不能编辑成功
pass#验证不能提交
self.browser.quit()
elif case==3:#编辑公司名称,不选择公司类型不能编辑成功
pass#验证不能提交
self.browser.quit()
开发者ID:Josen15,项目名称:kuaixiuscript,代码行数:25,代码来源:test_edit_company.py
示例10: SeleniumTestCase
class SeleniumTestCase(LiveServerTestCase):
"""
A base test case for Selenium, providing hepler methods for generating
clients and logging in profiles.
"""
def setUp(self):
"""
Base setup actions
"""
self.user = User.objects.create_superuser(
username='admin',
password='admin',
email='[email protected]'
)
self.browser = Browser()
super(SeleniumTestCase, self).setUp()
def open(self, url):
"""
Open a relative URL
"""
self.browser.visit("%s%s" % (self.live_server_url, url))
def tearDown(self):
"""
Base teardown action
"""
if hasattr(self, 'browser'):
self.browser.quit()
super(SeleniumTestCase, self).tearDown()
开发者ID:selevit,项目名称:keymaster2,代码行数:34,代码来源:__init__.py
示例11: TestViews
class TestViews(unittest.TestCase):
def setUp(self):
""" Test setup """
self.browser = Browser("phantomjs")
self.process = multiprocessing.Process(target=app.run,
kwargs={"port": 8080})
self.process.start()
time.sleep(1)
def test_visit_index(self):
self.browser.visit("http://0.0.0.0:8080/")
self.assertEqual(self.browser.url, "http://0.0.0.0:8080/")
def test_visit_browse(self):
self.browser.visit("http://0.0.0.0:8080/browse")
self.assertEqual(self.browser.url, "http://0.0.0.0:8080/browse")
def test_visit_about(self):
self.browser.visit("http://0.0.0.0:8080/about")
self.assertEqual(self.browser.url, "http://0.0.0.0:8080/about")
def test_visit_redirect(self):
"""
When a non-existent song url is requested, the browser should be
redirected to the browse page
"""
self.browser.visit("http://0.0.0.0:8080/songs/lugubrious_lima_beans-love_lichtenstein")
self.assertEqual(self.browser.url, "http://0.0.0.0:8080/browse")
def tearDown(self):
""" Test teardown """
# Remove the tables and their data from the database
self.process.terminate()
self.browser.quit()
开发者ID:jlreeder,项目名称:whsongbook,代码行数:35,代码来源:test_views_acceptance.py
示例12: test_find_working_stream_fail
def test_find_working_stream_fail(self):
browser = Browser("firefox", extensions=["adblock.xpi"])
browser.visit("http://kinox.to/Stream/The_Big_Bang_Theory.html")
stream = script.watchSeries("http://kinox.to/Stream/The_Big_Bang_Theory.html", None)
sleep(5)
assert not stream.find_working_stream(browser)
browser.quit()
开发者ID:pafi1,项目名称:stream,代码行数:7,代码来源:test.py
示例13: _parse_article_html
def _parse_article_html(self, objectId, url, industry_press=None):
#browser.visit("http://www.businesswire.com/news/home/20150409005073/en")
browser = Browser("phantomjs")
browser.visit(url)
time.sleep(2)
html = browser.html
#html = requests.get(url).text
html = BeautifulSoup(html)
article = html.find("div", {"class":"bw-release-story"})
company_name = html.find("h3", {"itemprop":"sourceOrganization"})
company_name = company_name.find("span", {"itemprop":"name"})
vals = [article, company_name]
cols = ["article", "company_name"]
#TODO - itemprop="name" company_name
#TODO - persist in parse
vals = [self.remove_non_ascii(i.text) if i else "" for i in vals]
data = dict(zip(cols, vals))
#print data["company_name"]
print data
#q.enqueue(ClearSpark()._bulk_company_info, data["company_name"])
if industry_press:
r = Parse().update("IndustryPress", objectId, data)
else:
r = Parse().update("Press", objectId, data)
print r.json()
browser.quit()
开发者ID:john2x,项目名称:scaling-fortnight,代码行数:27,代码来源:press.py
示例14: newgroup
class newgroup(object):
def __init__(self,browser_type):
self.browser_type=browser_type
self.site='http://www.kuaixiuagency.com'#登录页面
self.url=''#新增分组页面
def config(self,name='',admin=''):
self.name=name
self.admin=admin
def verify(self,case):
self._fill_form()
if case==1:#输入分组名称,选择管理员可以新增分组成功
pass
if True:#验证输入的名称是否和输入一致,选择的管理员是否一致
self.browser.quit()
return u'通过'
else:
self.browser.quit()
return u'失败'
elif case==2:#输入分组名称,不选择管理员不能新增成功
pass#验证不能提交
self.browser.quit()
elif case==3:#选择管理员不输入分组名称不能新增成功
pass#验证不能提交,有错误提示
self.browser.quit()
elif case==4:#输入已有的分组名称不能新增成功
pass#不能提交
self.browser.quit()
def _login(self):#登录
self.browser=Browser(self.browser_type)
self.browser.visit(self.site)
def _fill_form(self):#管理员身份登录
self._login()
开发者ID:Josen15,项目名称:kuaixiuscript,代码行数:32,代码来源:test_add_group.py
示例15: closeadmin
class closeadmin(object):
def __init__(self,browser_type):
self.browser_type=browser_type
self.site='http://www.kuaixiuagency.com'#登录页面
def verify(self,case):
self._fill_form()
if case==1:#在管理员列表可以关闭
pass
if True:#关闭的管理员不能登录
self.browser.quit()
return u'通过'
else:
self.browser.quit()
return u'失败'
elif case==2:#已关闭的管理员不能重复关闭
pass#关闭后没有关闭按钮
self.browser.quit()
elif case==3:#关闭的管理员可以开启
pass#开启后可以登录
self.browser.quit()
def _login(self):#登录
self.browser=Browser(self.browser_type)
self.browser.visit(self.site)
def _fill_form(self):#填写用户名密码
self._login()
开发者ID:Josen15,项目名称:kuaixiuscript,代码行数:27,代码来源:test_close_admin.py
示例16: webkit2png
def webkit2png(url, image_file_path, browser=None, wait_time=0):
new_browser = False
try:
if not browser:
browser = Browser('phantomjs')
new_browser = True
browser.visit(url)
if browser.status_code.is_success():
if wait_time > 0:
time.sleep(wait_time)
browser.driver.save_screenshot(image_file_path)
image = Image.open(image_file_path)
image.load()
if is_transparent(image) and False:
no_alpha = Image.new('L', image.size, (255))
no_alpha.paste(image, mask=image.split()[-1])
else:
no_alpha = image.convert('L')
# Convert to black and white imageage.
bw = no_alpha.convert('L')
# bw = bw.filter(ImageFilter.MedianFilter)
# White background.
bg = Image.new('L', image.size, 255)
bbox = ImageChops.difference(bw, bg).getbbox()
if bbox:
image = image.crop(bbox)
image.save(image_file_path)
finally:
if new_browser:
browser.quit()
开发者ID:acabhishek942,项目名称:html2latex,代码行数:30,代码来源:webkit2png.py
示例17: LiveServerTestCase
class LiveServerTestCase(TestCaseMixin, BaseLiveServerTestCase):
"""Base test case for in-browser functional tests."""
initial_url = None
login_button_value = 'Log in'
def login(self):
self.browser.fill('username', self.username)
self.browser.fill('password', self.password)
self.browser.find_by_value(self.login_button_value).click()
def create_staff_user(self, **kwargs):
kwargs.setdefault('is_staff', True)
kwargs.setdefault('is_superuser', True)
return super(LiveServerTestCase, self).create_user(**kwargs)
def setUp(self):
self.browser = Browser('django')
if self.initial_url is not None:
self.browser.visit("{}{}".format(
self.live_server_url,
self.initial_url,
))
def tearDown(self):
self.browser.quit()
开发者ID:sqlviz,项目名称:sqlviz,代码行数:27,代码来源:testcases.py
示例18: __init__
class BrowserManager:
def __init__(self):
self._lock = False
def bootup(self):
self._display = Display(visible=0, size=(1024, 768))
self._display.start()
profile = {}
if 'HTTP_PROXY' in os.environ:
proxy_url = os.environ['HTTP_PROXY']
proxy_server = proxy_url.split(':')[1][2:]
proxy_port = proxy_url.split(':')[-1]
profile['network.proxy.type'] = 1
profile['network.proxy.http'] = proxy_server
profile['network.proxy.http_port'] = proxy_port
profile['network.proxy.https'] = proxy_server
profile['network.proxy.https_port'] = proxy_port
self.browser = Browser(profile_preferences=profile)
def obtain(self,background):
while self._lock:
background.wait('Browser lock', 15)
self._lock = True
return self.browser
def release(self,background):
self._lock = False
def shutdown(self):
self.browser.quit()
self._display.stop()
开发者ID:adrian-r,项目名称:solar_radiation_model,代码行数:27,代码来源:worker_manager.py
示例19: SplinterThesis
class SplinterThesis(object):
def __init__(self):
self.browser = Browser("phantomjs", wait_time=10)
#访问网页
def get_html(self, url):
self.browser.visit(url)
return self.browser
#查找下载地址
def get_down_url(self, down_head, browser):
result = browser.find_link_by_text("下载全文")
down_url = ""
if result:
result = str(result["onclick"]).split("'")
temp_url = down_head + result[1]
browser.visit(temp_url)
result = browser.find_link_by_text("下载地址")
if browser and result["href"]:
down_url = result["href"]
return down_url
def main(self, down_url, url):
html_url = down_url + url
browser = self.get_html(html_url)
down_url = self.get_down_url(down_url, browser)
return down_url
开发者ID:happyin3,项目名称:captchaimgs,代码行数:29,代码来源:thesisclass.py
示例20: test_find_working_stream_success
def test_find_working_stream_success(self):
browser = Browser("firefox", extensions=["adblock.xpi"])
browser.visit("https://kinox.to/Stream/Poltergeist-2.html")
stream = script.watchSeries("https://kinox.to/Stream/Poltergeist-2.html", None)
sleep(5)
assert stream.find_working_stream(browser)
browser.quit()
开发者ID:pafi1,项目名称:stream,代码行数:7,代码来源:test.py
注:本文中的splinter.Browser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论