Scraping web data behind web forms

The most difficult scenario for web scraping is when data is hidden behind multiple pages that can only be accessed entering information into web forms. There are a few approaches that might work in these cases, with varying degree of difficulty and reliability, but in my experience the best method is to use Selenium.

Selenium automates web browsing sessions, and was originally designed for testing purposes. You can simulate clicks, enter information into web forms, add some waiting time between clicks, etc.

To learn how it works, we will scrape the website Monitor Legislativo, which provides information about the candidates in the recent Venezuelan legislative elections.

url <- 'http://eligetucandidato.org/filtro/'

As you can see, the information we want to scrape is hidden behind these two selectors. Let’s see how we can use Selenium to scrape it.

The first step is to load the two packages associated to RSelenium. Then, we will start a headless browser running in the background.

library(RSelenium)
library(wdman)

server <- phantomjs(port=4440L, verbose=FALSE)
browser <- remoteDriver(browserName = "phantomjs", port=4440L)

Note that you may need to change the server port. Now we can open an instance of PhantomJS and navigate to the URL

browser$open()
## [1] "Connecting to remote server"
## $browserName
## [1] "phantomjs"
## 
## $version
## [1] "2.1.1"
## 
## $driverName
## [1] "ghostdriver"
## 
## $driverVersion
## [1] "1.2.0"
## 
## $platform
## [1] "linux-unknown-64bit"
## 
## $javascriptEnabled
## [1] TRUE
## 
## $takesScreenshot
## [1] TRUE
## 
## $handlesAlerts
## [1] FALSE
## 
## $databaseEnabled
## [1] FALSE
## 
## $locationContextEnabled
## [1] FALSE
## 
## $applicationCacheEnabled
## [1] FALSE
## 
## $browserConnectionEnabled
## [1] FALSE
## 
## $cssSelectorsEnabled
## [1] TRUE
## 
## $webStorageEnabled
## [1] FALSE
## 
## $rotatable
## [1] FALSE
## 
## $acceptSslCerts
## [1] FALSE
## 
## $nativeEvents
## [1] TRUE
## 
## $proxy
## $proxy$proxyType
## [1] "direct"
## 
## 
## $id
## [1] "7165f1b0-76a4-11e7-a4af-cb5d1c0436c3"
browser$navigate(url)

Here’s how we would check that it worked:

browser$getPageSource()
## [[1]]
## [1] "<!DOCTYPE html><html lang=\"es-ES\" class=\" js flexbox canvas canvastext no-webgl touch no-geolocation postmessage websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent no-video no-audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths js_active  vc_mobile  vc_transform \" style=\"height: auto; overflow: auto;\"><head>\n\t<meta charset=\"UTF-8\">\n\t\n\t<title>Elige Tu Candidato |   Resultados de la consulta</title>\n\n\t\n\t\t\t\n\t\t\t\t\t\t<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,user-scalable=no\">\n\t\t\n\t<link rel=\"profile\" href=\"http://gmpg.org/xfn/11\">\n\t<link rel=\"pingback\" href=\"http://eligetucandidato.org/xmlrpc.php\">\n\t<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"http://eligetucandidato.org/wp-content/uploads/2015/09/fav.png\">\n\t<link rel=\"apple-touch-icon\" href=\"http://eligetucandidato.org/wp-content/uploads/2015/09/fav.png\">\n\t<link href=\"//fonts.googleapis.com/css?family=Raleway:100,200,300,400,500,600,700,800,900,300italic,400italic|Raleway:100,200,300,400,500,600,700,800,900,300italic,400italic|Lato:100,200,300,400,500,600,700,800,900,300italic,400italic&amp;subset=latin,latin-ext\" rel=\"stylesheet\" type=\"text/css\">\n<link rel=\"alternate\" type=\"application/rss+xml\" title=\"Elige Tu Candidato » Feed\" href=\"http://eligetucandidato.org/feed/\">\n<link rel=\"alternate\" type=\"application/rss+xml\" title=\"Elige Tu Candidato » RSS de los comentarios\" href=\"http://eligetucandidato.org/comments/feed/\">\n\t\t<div class=\"fit-vids-style\" id=\"fit-vids-style\" style=\"display: none;\">­<style>                 .fluid-width-video-wrapper {                   width: 100%;                                position: relative;                         padding: 0;                      \t\t\t\t\t min-height: 1px;                         }                                                                                       .fluid-width-video-wrapper iframe,          .fluid-width-video-wrapper object,          .fluid-width-video-wrapper embed {             position: absolute;                         top: 0;                                     left: 0;                                    width: 100%;                                height: 100%;                            }                                         </style></div><script async=\"\" src=\"//www.google-analytics.com/analytics.js\"></script><script async=\"\" src=\"//www.google-analytics.com/analytics.js\"></script><script async=\"\" src=\"//www.google-analytics.com/analytics.js\"></script><script type=\"text/javascript\">\n\t\t\twindow._wpemojiSettings = {\"baseUrl\":\"http:\\/\\/s.w.org\\/images\\/core\\/emoji\\/72x72\\/\",\"ext\":\".png\",\"source\":{\"concatemoji\":\"http:\\/\\/eligetucandidato.org\\/wp-includes\\/js\\/wp-emoji-release.min.js?ver=4.3.1\"}};\n\t\t\t!function(a,b,c){function d(a){var c=b.createElement(\"canvas\"),d=c.getContext&&c.getContext(\"2d\");return d&&d.fillText?(d.textBaseline=\"top\",d.font=\"600 32px Arial\",\"flag\"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement(\"script\");c.src=a,c.type=\"text/javascript\",b.getElementsByTagName(\"head\")[0].appendChild(c)}var f,g;c.supports={simple:d(\"simple\"),flag:d(\"flag\")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener(\"DOMContentLoaded\",g,!1),a.addEventListener(\"load\",g,!1)):(a.attachEvent(\"onload\",g),b.attachEvent(\"onreadystatechange\",function(){\"complete\"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);\n\t\t</script><script src=\"http://eligetucandidato.org/wp-includes/js/wp-emoji-release.min.js?ver=4.3.1\" type=\"text/javascript\"></script>\n\t\t<style type=\"text/css\">\nimg.wp-smiley,\nimg.emoji {\n\tdisplay: inline !important;\n\tborder: none !important;\n\tbox-shadow: none !important;\n\theight: 1em !important;\n\twidth: 1em !important;\n\tmargin: 0 .07em !important;\n\tvertical-align: -0.1em !important;\n\tbackground: none !important;\n\tpadding: 0 !important;\n}\n</style>\n<link rel=\"stylesheet\" id=\"svc-fontawosem-css-css\" href=\"http://eligetucandidato.org/wp-content/plugins/svc-post-grid-addon/assets/css/font-awesome.min.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"svc-front-css-css\" href=\"http://eligetucandidato.org/wp-content/plugins/svc-post-grid-addon/assets/css/front.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"rs-plugin-settings-css\" href=\"http://eligetucandidato.org/wp-content/plugins/revslider/public/assets/css/settings.css?ver=5.0.2\" type=\"text/css\" media=\"all\">\n<style id=\"rs-plugin-settings-inline-css\" type=\"text/css\">\n.tp-caption a{color:#FFF;text-shadow:none;-webkit-transition:all 0.2s ease-out;-moz-transition:all 0.2s ease-out;-o-transition:all 0.2s ease-out;-ms-transition:all 0.2s ease-out}.tp-caption a:hover{color:#FFF}\n</style>\n<link rel=\"stylesheet\" id=\"rotatingtweets-css\" href=\"http://eligetucandidato.org/wp-content/plugins/rotatingtweets/css/style.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"js_composer_front-css\" href=\"http://eligetucandidato.org/wp-content/plugins/js_composer/assets/css/js_composer.css?ver=4.7\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"default_style-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/style.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"qode-font-awesome-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/font-awesome/css/font-awesome.min.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"qode-elegant-icons-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/elegant-icons/style.min.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"stylesheet-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/stylesheet.min.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"webkit-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/webkit_stylesheet.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"safari-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/safari_stylesheet.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"style_dynamic-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/style_dynamic.css?ver=1444319657\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"responsive-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/responsive.min.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"style_dynamic_responsive-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/style_dynamic_responsive.css?ver=1444319657\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"custom_css-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/css/custom_css.css?ver=1444319657\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"childstyle-css\" href=\"http://eligetucandidato.org/wp-content/themes/eligecandidato-child/style.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"ultimate-style-min-css\" href=\"http://eligetucandidato.org/wp-content/plugins/Ultimate_VC_Addons/assets/min-css/ultimate.min.css?ver=3.13.3\" type=\"text/css\" media=\"all\">\n<link rel=\"stylesheet\" id=\"bsf-Defaults-css\" href=\"http://eligetucandidato.org/wp-content/uploads/smile_fonts/Defaults/Defaults.css?ver=4.3.1\" type=\"text/css\" media=\"all\">\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-includes/js/jquery/jquery.js?ver=1.11.3\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/plugins/revslider/public/assets/js/jquery.themepunch.tools.min.js?ver=5.0.2\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/plugins/revslider/public/assets/js/jquery.themepunch.revolution.min.js?ver=5.0.2\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/plugins/Ultimate_VC_Addons/assets/min-js/ultimate.min.js?ver=3.13.3\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/plugins/google-analyticator/external-tracking.min.js?ver=6.4.9\"></script>\n<link rel=\"EditURI\" type=\"application/rsd+xml\" title=\"RSD\" href=\"http://eligetucandidato.org/xmlrpc.php?rsd\">\n<link rel=\"wlwmanifest\" type=\"application/wlwmanifest+xml\" href=\"http://eligetucandidato.org/wp-includes/wlwmanifest.xml\"> \n<meta name=\"generator\" content=\"WordPress 4.3.1\">\n<link rel=\"canonical\" href=\"http://eligetucandidato.org/filtro/\">\n<link rel=\"shortlink\" href=\"http://eligetucandidato.org/?p=1734\">\n    <style>\n\t.svc_post_grid_list_container{ display:none;}\n\t#loader {background-image: url(\"http://eligetucandidato.org/wp-content/plugins/svc-post-grid-addon/inc/../addons/post-grid/css/loader.GIF\");}\n\t</style>\n    \t<style type=\"text/css\">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>\n<meta name=\"generator\" content=\"Powered by Visual Composer - drag and drop page builder for WordPress.\">\n<!--[if lte IE 9]><link rel=\"stylesheet\" type=\"text/css\" href=\"http://eligetucandidato.org/wp-content/plugins/js_composer/assets/css/vc_lte_ie9.css\" media=\"screen\"><![endif]--><!--[if IE  8]><link rel=\"stylesheet\" type=\"text/css\" href=\"http://eligetucandidato.org/wp-content/plugins/js_composer/assets/css/vc-ie8.css\" media=\"screen\"><![endif]--><meta name=\"generator\" content=\"Powered by Slider Revolution 5.0.2 - responsive, Mobile-Friendly Slider Plugin for WordPress with comfortable drag and drop interface.\">\n<!-- Google Analytics Tracking by Google Analyticator 6.4.9: http://www.videousermanuals.com/google-analyticator/ -->\n<script type=\"text/javascript\">\n    var analyticsFileTypes = [''];\n    var analyticsSnippet = 'disabled';\n    var analyticsEventTracking = 'enabled';\n</script>\n<script type=\"text/javascript\">\n\t(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\tm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\tga('create', 'UA-XXXXXXXX-X', 'auto');\n \n\t\n\n\tga('send', 'pageview');\n\t  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n  ga('create', 'UA-68657759-1', 'auto');\n  ga('send', 'pageview');\n\n</script>\n<noscript>&lt;style&gt; .wpb_animate_when_almost_visible { opacity: 1; }&lt;/style&gt;</noscript><style>/** Ultimate: Media Responsive **/ @media (max-width: 1199px) { }@media (max-width: 991px)  { }@media (max-width: 767px)  { }@media (max-width: 479px)  { }/** Ultimate: Media Responsive - **/</style></head>\n\n<body class=\"page page-id-1734 page-template page-template-full_width page-template-full_width-php  qode-child-theme-ver-1.0.0 qode-theme-ver-7.6.1 wpb-js-composer js-comp-ver-4.7 vc_responsive safari_browser\" style=\"height: auto; overflow: auto;\">\n\n\t\t\t\t<div class=\"ajax_loader\"><div class=\"ajax_loader_1\"><div class=\"pulse\"></div></div></div>\n\t\t\t\t\t<div class=\"wrapper\">\n\t<div class=\"wrapper_inner\">\n\t<!-- Google Analytics start -->\n\t\t<!-- Google Analytics end -->\n\n\t\n\n\n<header class=\"scroll_header_top_area  fixed scrolled_not_transparent with_border page_header\">\n    <div class=\"header_inner clearfix\">\n\n\t\t\n\t\t\t\t\t<form role=\"search\" action=\"http://eligetucandidato.org/\" class=\"qode_search_form_2\" method=\"get\">\n\t\t\t\t\t\t\t\t\t\t<div class=\"form_holder_outer\">\n\t\t\t\t\t\t\t<div class=\"form_holder\">\n\t\t\t\t\t\t\t\t<input type=\"text\" placeholder=\"Buscar\" name=\"s\" class=\"qode_search_field\" autocomplete=\"off\">\n\t\t\t\t\t\t\t\t<a class=\"qode_search_submit\" href=\"javascript:void(0)\">\n                                    <i class=\"qode_icon_font_awesome fa fa-search \"></i>\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t</form>\n\n\t\t\t\t\n\t\t<div class=\"header_top_bottom_holder\">\n\t\t<div class=\"header_bottom clearfix\" style=\"\">\n\t\t                    \t\t\t\t\t<div class=\"header_inner_left\">\n                        \t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"mobile_menu_button\">\n                                <span>\n                                    <i class=\"qode_icon_font_awesome fa fa-bars \"></i>                                </span>\n                            </div>\n\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"logo_wrapper\">\n                            \t\t\t\t\t\t\t<div class=\"q_logo\">\n\t\t\t\t\t\t\t\t<a href=\"http://eligetucandidato.org/\" style=\"height: 80px; visibility: visible;\">\n\t\t\t\t\t\t\t\t\t<img class=\"normal\" src=\"http://eligetucandidato.org/wp-content/uploads/2015/09/logo.png\" alt=\"Logo\" style=\"height: 100%;\">\n\t\t\t\t\t\t\t\t\t<img class=\"light\" src=\"http://eligetucandidato.org/wp-content/uploads/2015/09/logo.png\" alt=\"Logo\" style=\"height: 100%;\">\n\t\t\t\t\t\t\t\t\t<img class=\"dark\" src=\"http://eligetucandidato.org/wp-content/uploads/2015/09/logo.png\" alt=\"Logo\" style=\"height: 100%;\">\n\t\t\t\t\t\t\t\t\t<img class=\"sticky\" src=\"http://eligetucandidato.org/wp-content/uploads/2015/09/logo.png\" alt=\"Logo\" style=\"height: 100%;\">\n\t\t\t\t\t\t\t\t\t<img class=\"mobile\" src=\"http://eligetucandidato.org/wp-content/uploads/2015/09/logo.png\" alt=\"Logo\" style=\"height: 100%;\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</div>\n                            \t\t\t\t\t\t</div>\n                                                \t\t\t\t\t</div>\n                    \t\t\t\t\t                                                \t\t\t\t\t\t\t<div class=\"header_inner_right\">\n                                <div class=\"side_menu_button_wrapper right\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                    <div class=\"side_menu_button\">\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"search_button search_slides_from_header_bottom normal\" href=\"javascript:void(0)\">\n                                                <i class=\"qode_icon_font_awesome fa fa-search \"></i>\t\t\t\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                                                                                                    </div>\n                                </div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t<nav class=\"main_menu drop_down \">\n\t\t\t\t\t\t<ul id=\"menu-principal\" class=\"\"><li id=\"nav-menu-item-144\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-home  wide icons\"><a href=\"http://eligetucandidato.org/\" class=\"\"><i class=\"menu_icon fa-home fa\"></i><span>Inicio</span><span class=\"plus\"></span></a></li>\n<li id=\"nav-menu-item-31\" class=\"menu-item menu-item-type-post_type menu-item-object-page  wide icons\"><a href=\"http://eligetucandidato.org/perfil-del-diputado/\" class=\"\"><i class=\"menu_icon fa-male fa\"></i><span>Perfil Ideal</span><span class=\"plus\"></span></a></li>\n<li id=\"nav-menu-item-1749\" class=\"menu-item menu-item-type-post_type menu-item-object-page  narrow\"><a href=\"http://eligetucandidato.org/noticias-2/\" class=\"\"><i class=\"menu_icon fa-newspaper-o fa\"></i><span>Noticias</span><span class=\"plus\"></span></a></li>\n<li id=\"nav-menu-item-4384\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children  has_sub narrow\"><a href=\"#\" class=\"\"><i class=\"menu_icon fa-users fa\"></i><span>Candidatos</span><span class=\"plus\"></span></a>\n<div class=\"second\" style=\"height: 0px;\"><div class=\"inner\"><ul>\n\t<li id=\"nav-menu-item-30\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/candidatos/\" class=\"\"><i class=\"menu_icon fa-users fa\"></i><span>Busca tu Candidato</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-4681\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/representacion-indigena/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Representación Indígena</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-3478\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a target=\"_blank\" href=\"http://eligetucandidato.org/wp-content/uploads/2015/10/Plan-de-Gestión-Elecciones-Parlamentarias-20151.pdf\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Propuestas de la MUD</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-5799\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://eligetucandidato.org/wp-content/uploads/2015/10/Programa-de-gestion-GPP.pdf\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Propuestas del GPP</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-4435\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://eligetucandidato.org/wp-content/uploads/2015/10/Conoce-tu-Plancha.pdf\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Boletas de votación</span><span class=\"plus\"></span></a></li>\n</ul></div></div>\n</li>\n<li id=\"nav-menu-item-395\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children  has_sub narrow\"><a href=\"#\" class=\"\"><i class=\"menu_icon blank fa\"></i><span><i class=\"iconcapito iconmenup\" style=\"margin: 5px 70px 0;\"></i> Asamblea Nacional</span><span class=\"plus\"></span></a>\n<div class=\"second\" style=\"height: 0px;\"><div class=\"inner\"><ul>\n\t<li id=\"nav-menu-item-5071\" class=\"menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children sub\"><a href=\"http://eligetucandidato.org/?page_id=5069\" class=\" no_link\" style=\"cursor: default;\" onclick=\"JavaScript: return false;\"><i class=\"menu_icon blank fa\"></i><span>¿Para que sirve la Asamblea Nacional?</span><span class=\"plus\"></span><i class=\"q_menu_arrow fa fa-angle-right\"></i></a>\n\t<ul>\n\t\t<li id=\"nav-menu-item-4340\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/para-que-sirve-la-asamblea-nacional/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>¿Para qué sirve la Asamblea Nacional?</span><span class=\"plus\"></span></a></li>\n\t\t<li id=\"nav-menu-item-5072\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/dice-la-constitucion/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Dice la Constitución</span><span class=\"plus\"></span></a></li>\n\t\t<li id=\"nav-menu-item-5068\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/opina-la-gente/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Opina la gente</span><span class=\"plus\"></span></a></li>\n\t</ul>\n</li>\n\t<li id=\"nav-menu-item-5559\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://transparencia.org.ve/wp-content/uploads/2015/11/Quinquenio-2015.pdf\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Balance 2011-2015</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-398\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/historia/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Historia</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-5106\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/mayorias-de-la-proxima-asamblea/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Mayorías de la próxima Asamblea</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-401\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/diputados/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Composición</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-4149\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://http://monitorlegislativo.net/informes-legislativos/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Gestión Asamblea Nacional 2011-2015</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-4151\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://http://monitorlegislativo.net/leyes-aprobadas/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Leyes aprobadas 2011-2015</span><span class=\"plus\"></span></a></li>\n\t<li id=\"nav-menu-item-402\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children sub\"><a href=\"#\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>ABC Legislativo</span><span class=\"plus\"></span><i class=\"q_menu_arrow fa fa-angle-right\"></i></a>\n\t<ul>\n\t\t<li id=\"nav-menu-item-403\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-iniciativa-popular/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Iniciativa Popular</span><span class=\"plus\"></span></a></li>\n\t\t<li id=\"nav-menu-item-405\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-plenaria/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Funcionamiento de la Plenaria</span><span class=\"plus\"></span></a></li>\n\t\t<li id=\"nav-menu-item-409\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-reglamento-interno/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Reglamento Interno</span><span class=\"plus\"></span></a></li>\n\t\t<li id=\"nav-menu-item-413\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-sancion-de-leyes/\" class=\"\"><i class=\"menu_icon blank fa\"></i><span>Sanción de leyes</span><span class=\"plus\"></span></a></li>\n\t</ul>\n</li>\n</ul></div></div>\n</li>\n<li id=\"nav-menu-item-4972\" class=\"menu-item menu-item-type-post_type menu-item-object-page  narrow\"><a href=\"http://eligetucandidato.org/abusos/\" class=\"\"><i class=\"menu_icon fa-thumbs-o-down fa\"></i><span>Abusos</span><span class=\"plus\"></span></a></li>\n<li id=\"nav-menu-item-3636\" class=\"menu-item menu-item-type-post_type menu-item-object-page  narrow\"><a href=\"http://eligetucandidato.org/contactos/\" class=\"\"><i class=\"menu_icon fa-phone fa\"></i><span>Contáctenos</span><span class=\"plus\"></span></a></li>\n</ul>\t\t\t\t\t\t</nav>\n\t\t\t\t\t\t                        \t\t\t\t\t\t\t\t\t\t<nav class=\"mobile_menu\">\n                        <ul id=\"menu-principal-1\" class=\"\"><li id=\"mobile-menu-item-144\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-home \"><a href=\"http://eligetucandidato.org/\" class=\"\"><span>Inicio</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n<li id=\"mobile-menu-item-31\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/perfil-del-diputado/\" class=\"\"><span>Perfil Ideal</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n<li id=\"mobile-menu-item-1749\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/noticias-2/\" class=\"\"><span>Noticias</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n<li id=\"mobile-menu-item-4384\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children  has_sub\"><a href=\"#\" class=\"\"><span>Candidatos</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span>\n<ul class=\"sub_menu\">\n\t<li id=\"mobile-menu-item-30\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/candidatos/\" class=\"\"><span>Busca tu Candidato</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-4681\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/representacion-indigena/\" class=\"\"><span>Representación Indígena</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-3478\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a target=\"_blank\" href=\"http://eligetucandidato.org/wp-content/uploads/2015/10/Plan-de-Gestión-Elecciones-Parlamentarias-20151.pdf\" class=\"\"><span>Propuestas de la MUD</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-5799\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://eligetucandidato.org/wp-content/uploads/2015/10/Programa-de-gestion-GPP.pdf\" class=\"\"><span>Propuestas del GPP</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-4435\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://eligetucandidato.org/wp-content/uploads/2015/10/Conoce-tu-Plancha.pdf\" class=\"\"><span>Boletas de votación</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n</ul>\n</li>\n<li id=\"mobile-menu-item-395\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children  has_sub\"><a href=\"#\" class=\"\"><span><i class=\"iconcapito iconmenup\" style=\"margin: 5px 70px 0;\"></i> Asamblea Nacional</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span>\n<ul class=\"sub_menu\">\n\t<li id=\"mobile-menu-item-5071\" class=\"menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children  has_sub\"><h3><span>¿Para que sirve la Asamblea Nacional?</span></h3><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span>\n\t<ul class=\"sub_menu\">\n\t\t<li id=\"mobile-menu-item-4340\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/para-que-sirve-la-asamblea-nacional/\" class=\"\"><span>¿Para qué sirve la Asamblea Nacional?</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t\t<li id=\"mobile-menu-item-5072\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/dice-la-constitucion/\" class=\"\"><span>Dice la Constitución</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t\t<li id=\"mobile-menu-item-5068\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/opina-la-gente/\" class=\"\"><span>Opina la gente</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t</ul>\n</li>\n\t<li id=\"mobile-menu-item-5559\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://transparencia.org.ve/wp-content/uploads/2015/11/Quinquenio-2015.pdf\" class=\"\"><span>Balance 2011-2015</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-398\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/historia/\" class=\"\"><span>Historia</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-5106\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/mayorias-de-la-proxima-asamblea/\" class=\"\"><span>Mayorías de la próxima Asamblea</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-401\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/diputados/\" class=\"\"><span>Composición</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-4149\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://http://monitorlegislativo.net/informes-legislativos/\" class=\"\"><span>Gestión Asamblea Nacional 2011-2015</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-4151\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://http://monitorlegislativo.net/leyes-aprobadas/\" class=\"\"><span>Leyes aprobadas 2011-2015</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t<li id=\"mobile-menu-item-402\" class=\"menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children  has_sub\"><a href=\"#\" class=\"\"><span>ABC Legislativo</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span>\n\t<ul class=\"sub_menu\">\n\t\t<li id=\"mobile-menu-item-403\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-iniciativa-popular/\" class=\"\"><span>Iniciativa Popular</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t\t<li id=\"mobile-menu-item-405\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-plenaria/\" class=\"\"><span>Funcionamiento de la Plenaria</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t\t<li id=\"mobile-menu-item-409\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-reglamento-interno/\" class=\"\"><span>Reglamento Interno</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t\t<li id=\"mobile-menu-item-413\" class=\"menu-item menu-item-type-custom menu-item-object-custom \"><a href=\"http://monitorlegislativo.net/abc-legislativo-sancion-de-leyes/\" class=\"\"><span>Sanción de leyes</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n\t</ul>\n</li>\n</ul>\n</li>\n<li id=\"mobile-menu-item-4972\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/abusos/\" class=\"\"><span>Abusos</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n<li id=\"mobile-menu-item-3636\" class=\"menu-item menu-item-type-post_type menu-item-object-page \"><a href=\"http://eligetucandidato.org/contactos/\" class=\"\"><span>Contáctenos</span></a><span class=\"mobile_arrow\"><i class=\"fa fa-angle-right\"></i><i class=\"fa fa-angle-down\"></i></span></li>\n</ul>\t\t\t\t\t</nav>\n\t\t\t\t</div>\n\t</div>\n\t</div>\n\n</header>\n\t\t\n\n    \t\t<a id=\"back_to_top\" href=\"#\">\n\t\t\t<span class=\"fa-stack\">\n\t\t\t\t<i class=\"fa fa-arrow-up\" style=\"\"></i>\n\t\t\t</span>\n\t\t</a>\n\t    \t\n    \n\t\t\n\t\n    \n<div class=\"content \" style=\"padding-top: 0px;\">\n\t\t\t\t\t\t<div class=\"content_inner  \">\n\t\t\t\t\t\t\t\t\t<div class=\"title_outer title_without_animation\" data-height=\"125\">\n\t\t<div class=\"title title_size_small  position_left \" style=\"height:125px;background-color:#F6F6F6;\">\n\t\t\t<div class=\"image not_responsive\"></div>\n\t\t\t\t\t\t\t\t\t\t<div class=\"title_holder\" style=\"padding-top:81px;height:44px;\">\n\t\t\t\t\t<div class=\"container\">\n\t\t\t\t\t\t<div class=\"container_inner clearfix\">\n\t\t\t\t\t\t\t\t<div class=\"title_subtitle_holder\">\n                                                                \t\t\t\t\t\t\t\t\t<h1><span>Resultados de la consulta</span></h1>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                                            </div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t<div class=\"full_width\">\n\t<div class=\"full_width_inner\">\n\t\t\t\t\t\t\t\t\t\t\n         \n    \n<div class=\"content \" style=\"min-height: 347px; padding-top: 0px;\">\n\t\t\t\t\t\t<div class=\"content_inner  \">\n\t\t\t\t\t\t\t\t\t\n<div class=\"full_width\">\n\t<div class=\"full_width_inner gform_wrapper\">\n        \n       <table style=\"display: table;margin: auto;\">\n            <form action=\"http://eligetucandidato.org/filtro/\" name=\"form1\" method=\"post\" enctype=\"multipart/form-data\"></form>\n            <tbody><tr>\n                <td><select name=\"estado\" id=\"estado\" required=\"required\">\n                  <option value=\"\">Seleccione</option>\n                  <option value=\"Amazonas\">Amazonas</option>\n                    <option value=\"Anzoategui\">Anzoategui</option>\n                    <option value=\"Apure\">Apure</option>\n                    <option value=\"Aragua\">Aragua</option>\n                    <option value=\"Barinas\">Barinas</option>\n                    <option value=\"Boliva\">Bolívar</option>\n                    <option value=\"Carabobo\">Carabobo</option>\n                    <option value=\"Cojedes\">Cojedes</option>\n                    <option value=\"Delta Amacuro\">Delta Amacuro</option>\n                    <option value=\"Distrito Capital\">Distrito Capital</option>\n                    <option value=\"Falcón\">Falcón</option>\n                    <option value=\"Guárico\">Guárico</option>\n                    <option value=\"Mérida\">Mérida</option>\n                    <option value=\"Miranda\">Miranda</option>\n                    <option value=\"Lara\">Lara</option>\n                    <option value=\"Monagas\">Monagas</option>\n                    <option value=\"Nueva Esparta\">Nueva Esparta</option>\n                    <option value=\"Portuguesa\">Portuguesa</option>\n                    <option value=\"Sucre\">Sucre</option>\n                    <option value=\"Tachira\">Táchira</option>\n                    <option value=\"Trujillo\">Trujillo</option>\n                    <option value=\"Vargas\">Vargas</option>\n                    <option value=\"Yaracuy\">Yaracuy</option>\n                    <option value=\"Zulia\">Zulia</option>\n                    </select></td>\n                <td><select name=\"partido\" id=\"partido\" required=\"required\">\n                     <option value=\"\">Partido</option>\n                    <option value=\"PSUV\">GPP</option>\n                    <option value=\"MUD\">MUD</option>\n                    <option value=\"INDEPENDIENTE\">INDEPENDIENTE</option>\n            </select></td> \n\n                <td><input type=\"button\" name=\"enviar\" id=\"enviar\" value=\"Buscar\" style=\"cursor:pointer\"></td>\n            </tr>\n                \n        </tbody></table>\t\n        <script type=\"text/javascript\">\n            function indi() {\n               \n                var estado=document.getElementById('estado').value;     \n            switch (estado) {\n                  case 'Amazonas':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-amazonas/';\n                  break;\n                    \n                  case 'Anzoategui':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-anzoategui/';\n                  break;\n                    \n                  case 'Apure':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-apure/';\n                  break;\n                    \n                  case 'Aragua':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-aragua/';\n                  break;\n                    \n                  case 'Barinas':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-barinas/';\n                  break;\n                    \n                  case 'Boliva':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-bolivar/';    \n                  break;\n                    \n                  case 'Carabobo':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-carabobo/';\n                  break;\n                    \n                  case 'Cojedes':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-cojedes/';\n                  break;\n                    \n                  case 'Delta Amacuro':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-delta-amacuro/';\n                  break;\n                    \n                  case 'Distrito Capital':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-distrito-capital/';\n                  break;\n                    \n                  case 'Falcón':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-falcon/'; \n                  break;\n                    \n                  case 'Guárico':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-guarico/'; \n                  break;\n                    \n                  case 'Mérida':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-merida/'; \n                  break;\n                    \n                  case 'Miranda':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-miranda/'; \n                  break;\n                    \n                  case 'Lara':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-lara/'; \n                  break;\n                    \n                  case 'Monagas':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-monagas/'; \n                  break;\n                    \n                  case 'Nueva Esparta':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-nueva-esparta/'; \n                  break;\n                    \n                  case 'Portuguesa':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-portuguesa/'; \n                  break;\n                    \n                  case 'Sucre':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-sucre/'; \n                  break;\n                    \n                  case 'Tachira':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-tachira/'; \n                  break;\n                   \n                  case 'Trujillo':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-trujillo/'; \n                  break;\n                   \n                  case 'Vargas':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-vargas/'; \n                  break;\n                    \n                  case 'Yaracuy':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-yaracuy/'; \n                  break;\n                  \n                  case 'Zulia':\n                    window.location='http://eligetucandidato.org/candidatos-independientes-por-el-estado-zulia/';  \n                  break;\n\n                }\n                   \n                \n            }\n            \n            \n            document.getElementById('enviar').onclick=function(){\n              \n               var partido=document.getElementById('partido').value;\n                if(partido=='INDEPENDIENTE'){\n                    indi();\n                }else{\n                    document.form1.submit(); \n                } \n            }\n            \n        </script>\n\t</div>\n    \t\t<p>Disculpe no encontramos diputados voto lista para el estado seleccionado.</p>\n\t\t          </div>\n\n            \n\n          <div class=\"contenedorCand\">\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t\t\t\n\n   \n\n\t\t\t          </div>\n    \n\n\t\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t</div>\t\n\t\t\t\t\t<div class=\"content_bottom\">\n\t\t\t\t\t</div>\n\t\t\t\t\n\t</div>\n</div>\n\n\n\n\t<footer>\n\t\t<div class=\"footer_inner clearfix\">\n\t\t\t\t<div class=\"footer_top_holder\">\n            \t\t\t<div class=\"footer_top footer_top_full\">\n\t\t\t\t\t\t\t\t\t\t<div id=\"epx_vcsb_widget_36\" class=\"widget ERROPiX\\VC_Sidebar_Editor\\Main\"><div class=\"vc_row wpb_row section vc_row-fluid vc_custom_1441601202749\" style=\" text-align:left;\"><div class=\" full_section_inner clearfix\"><div class=\"wpb_column vc_column_container vc_col-sm-3\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_single_image wpb_content_element vc_align_left\">\n\t\t<div>\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t\n\t\t\t<div class=\"vc_single_image-wrapper  \"><img class=\"vc_single_image-img \" src=\"http://eligetucandidato.org/wp-content/uploads/2015/09/logoBlanco-209x90.png\" width=\"209\" height=\"90\" alt=\"logoBlanco-209x90\" title=\"logoBlanco-209x90\"></div>\n\t\t</div> \n\t\t</div>\n\t</div> </div></div><div class=\"wpb_column vc_column_container vc_col-sm-3\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element \">\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<h2><span style=\"color: #ffffff; font-size: 16px;\">Contáctanos</span></h2>\n<h2><span style=\"color: #ffffff; font-size: 12px; line-height: 1; display: block;\">gestionpublica@transparencia.org.ve</span></h2>\n\n\t\t</div> \n\t</div> </div></div><div class=\"wpb_column vc_column_container vc_col-sm-3\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element \">\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<h2><span style=\"color: #ffffff; font-size: 16px;\">Dirección: </span></h2>\n<h3 style=\"text-align: justify;\"><span style=\"color: #ffffff; font-size: 12px; line-height: 1; display: block;\">Av. Andrés Eloy Blanco. Edif. Cámara de Comercio de Caracas. Piso 2. Ofic. 2-15. Los Caobos Caracas 1050. Venezuela. RIF J-31128182-7</span></h3>\n\n\t\t</div> \n\t</div> </div></div><div class=\"wpb_column vc_column_container vc_col-sm-3\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_raw_code wpb_content_element wpb_raw_html\">\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<div style=\"display: table; margin: auto; width: 120px;\">\t\t\t\n  \n\n<p><a style=\"float: left;\" href=\"https://twitter.com/monitorAN\" target=\"_blank\"><br>\n<i class=\"ts-font-icon fa fa-twitter frame-enabled ts-radius-full\" style=\"background-color: #ffffff; width: 40px; height: 40px; font-size: 31px; color: #de6d27; padding: 10px 0 0 10px; border-radius: 50%;\"></i><br>\n</a></p>\n      </div>\n\t\t</div>\n\t</div>\n</div></div></div></div>\n</div>\t\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t</footer>\n\t\t\n</div>\n</div>\n<style type=\"text/css\">.vc_custom_1441601202749{margin-right: 40px !important;margin-left: 40px !important;}</style><script type=\"text/javascript\">\n/* <![CDATA[ */\nvar qodeLike = {\"ajaxurl\":\"http:\\/\\/eligetucandidato.org\\/wp-admin\\/admin-ajax.php\"};\n/* ]]> */\n</script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/qode-like.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/plugins.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/jquery.carouFredSel-6.2.1.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/lemmon-slider.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/jquery.fullPage.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/jquery.mousewheel.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/jquery.touchSwipe.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/plugins/js_composer/assets/lib/bower/isotope/dist/isotope.pkgd.min.js?ver=4.7\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/default_dynamic.js?ver=1444319657\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/default.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/themes/eligecandidato/js/custom_js.js?ver=1444319657\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-includes/js/comment-reply.min.js?ver=4.3.1\"></script>\n<script type=\"text/javascript\" src=\"http://eligetucandidato.org/wp-content/plugins/js_composer/assets/js/js_composer_front.js?ver=4.7\"></script>\n<script>\n  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n  ga('create', 'UA-68657759-1', 'auto');\n  ga('send', 'pageview');\n\n</script>\n\n</div></div></body></html>"

We can see what the website looks like at any time by taking screenshots. This will become very useful as we start playing with the web form.

browser$screenshot(display=TRUE)

Let’s assume we want to see the results of the state of Distrito Capital for the GPP party. First, let’s use selectorGadget to identify the elements that we’re trying to scrape. Then, click on the list of states and parties to find the exact state and party you would want to scrape.

state <- browser$findElement(using = 'id', value="estado")
state$sendKeysToElement(list("Distrito Capital"))
browser$screenshot(display=TRUE)

party <- browser$findElement(using = 'id', value="partido")
party$sendKeysToElement(list("GPP"))
browser$screenshot(display=TRUE)

That seemed to work! Finally, let’s find the information for the Send button and click on it.

send <- browser$findElement(using = 'id', value="enviar")
send$clickElement()
browser$screenshot(display=TRUE)

From this website, we want to scrape the URLs to each candidate’s page. Note that there are some duplicates, which we will need to clean. As in the previous cases, we can use selectorGadget to help us identify the information we want to extract. Then, for each of the elements, we will extract the URL.

links <- browser$findElements(using="css selector", value=".portfolio_title a")

urls <- c()
for (i in 1:length(links)){
    urls <- c(urls, 
        links[[i]]$getElementAttribute('href')[[1]])
}

# removing duplicates
urls <- urls[!duplicated(urls)]
urls
## [1] "http://eligetucandidato.org/perfil-candidato/?id=6432672"
## [2] "http://eligetucandidato.org/perfil-candidato/?id=4376240"

The final step would be to scrape the information from each of these candidate websites, and do all of this inside loops over states and parties, and then candidates. I will not cover the rest of the example in class, but I’m pasting the code below in case you want to use parts of it for your projects.

Before we switch topics, one more thing: it’s important to clean up after we scrape some data by closing the browser that we opened in the background.

browser$close()

And now, here’s the rest of the code:

############################################################
## first, we scrape the list of districts and parties
############################################################

url <- 'http://eligetucandidato.org/filtro/'
txt <- readLines(url)

estados <- txt[288:311]
estados <- gsub(".*>(.*)<.*", estados, repl="\\1")

partidos <- txt[315:317]
partidos <- gsub(".*>(.*)<.*", partidos, repl="\\1")

############################################################
## now, loop over pages to extract the URL for each candidate
############################################################

library(RSelenium)
library(RSelenium)
library(wdman)

server <- phantomjs(port=4446L, verbose=FALSE)
browser <- remoteDriver(browserName = "phantomjs", port=4446L)

browser$open()

candidatos <- c()

for (estado in estados){
    message(estado)
    for (partido in partidos){
        message(partido)

        browser$navigate(url)
        # input: estado
        Sys.sleep(1)
        more <- browser$findElement(using = 'id', value="estado")
        more$sendKeysToElement(list(estado))
        # input: partido
        Sys.sleep(1)
        more <- browser$findElement(using = 'id', value="partido")
        more$sendKeysToElement(list(partido))
        # click on "buscar"
        more <- browser$findElement(using = 'id', value="enviar")
        more$clickElement()
        # extracting URLS
        more <- browser$findElements(using = 'xpath', value="//a[@target='_self']")
        count <- 0
        while (length(more)<2 & count < 10){
            Sys.sleep(1)
            more <- browser$findElements(using = 'xpath', value="//a[@target='_self']")
            count <- count + 1
        }
        urls <- unlist(sapply(more, function(x) x$getElementAttribute('href')))
        urls <- unique(urls)

        candidatos <- c(candidatos, urls)
        message(length(urls), ' candidatos nuevos, ', length(candidatos), ' en total')


    }
}

writeLines(candidatos, con=file("candidatos-urls.txt"))

############################################################
## download the html code of candidates' URLS
############################################################

for (url in candidatos){
    id <- gsub('.*id=', '', url)
    filename <- paste0('html/', id, '.html')
    if (file.exists(filename)){ next }
    message(url)
    html <- readLines(url)
    writeLines(html, con=file(filename))
    Sys.sleep(2)
}

############################################################
## extract information from html
############################################################

fls <- list.files("html", full.names=TRUE)
df <- list()

for (i in 1:length(fls)){

    txt <- readLines(fls[i])

    # id
    id <- gsub('html/(.*).html', fls[i], repl="\\1")
    # name
    name <- txt[grep("displayCenter vc_single_image", txt)]
    name <- gsub(".*title=\"(.*)\">.*", name, repl='\\1')
    # partido
    partido <- txt[grep("Partido Político", txt)]
    partido <- gsub('.*</strong> (.*)</span.*', partido, repl="\\1")
    # edad
    edad <- txt[grep("Edad", txt)]
    edad <- gsub('.*ong>(.*)</span.*', edad, repl="\\1")
    # circuito
    circuito <- txt[grep("Circuito", txt)]
    circuito <- gsub('.*Circuito (.*)</span.*', circuito, repl="\\1")[1]
    # estado
    estado <- txt[grep("Circuito", txt)]
    estado <- gsub('.*\">(.*) –&nbsp;.*', estado, repl="\\1")[1]
    # twitter
    twitter <- txt[grep("fa-twitter.*@", txt)]
    twitter <- gsub('.*@(.*)</spa.*', twitter, repl="\\1")
    if (length(twitter)==0){ twitter <- NA }

    df[[i]] <- data.frame(
        id = id, name = name, partido = partido, edad = edad,
        circuito = circuito, estado = estado, twitter = twitter,
        stringsAsFactors=F)
}

df <- do.call(rbind, df)
df <- df[order(df$estado, df$partido, df$circuito),]

write.csv(df, file="venezuela-monitor-legislativo-data.csv",
    row.names=FALSE)