Created
July 2, 2013 08:18
-
-
Save danilobellini/5907591 to your computer and use it in GitHub Desktop.
Simple Splinter example with both XPath and CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Created on Tue Jul 2 05:17:13 2013 | |
# @author: Danilo de Jesus da Silva Bellini | |
# Simple Splinter example with both XPath and CSS | |
from splinter import Browser | |
from tempfile import NamedTemporaryFile | |
data = """ | |
<html><head><title>Splinter testing</title></head><body> | |
<select id="estado" name="estado"> | |
<option value="teste1">teste1</option> | |
<option value="teste2">teste2</option> | |
<option value="teste3">teste3</option> | |
<option value="teste4">teste4</option> | |
</select> | |
</body></html> | |
""" | |
with Browser() as br: | |
with NamedTemporaryFile() as f: | |
f.write(data) | |
f.flush() | |
br.visit("file://" + f.name) | |
xpath_options = br.find_by_xpath("//option") | |
css_options = br.find_by_css("option") | |
print(xpath_options[2]) | |
print(css_options[2]) | |
print(len(xpath_options)) | |
print(len(css_options)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment