Post request on python3 - python

I recently got into coding with python3 and decided to do a project where I can try to join the Joe Biden Campaign email list. However, my code seems to not be working since I am receiving errors as my response. Can someone help me out:
import http.client, urllib.parse
email = "theterminatingunicorn777#gmail.com"
connection = http.client.HTTPSConnection("go.joebiden.com")
connection.request("POST", "/page/s/join_the_team?source=website-joinpage", urllib.parse.urlencode(
{'email': email,
'firstname': "Terminating",
'lastname': "Unicorn",
'mobile': "2819573929",
'zip': '70655',
'custom-1572[0]': ''
}))
response = connection.getresponse()
print(response.status, response.reason)
data = response.read()
print(data)
print(email)
For reference, I am using the sign up link here: https://joebiden.com/join/
When I refer to errors, I am referring to the response from the post request:
<!DOCTYPE html>\n
<html lang="en-US" class="no-js">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- Google Tag Manager --><script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\':\r\n new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0],\r\n j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src=\r\n \'https://www.googletagmanager.com/gtm.js?id=\'+i+dl;f.parentNode.insertBefore(j,f);\r\n })(window,document,\'script\',\'dataLayer\',\'GTM-M96J785\');</script><!-- End Google Tag Manager -->
<title>Joe Biden for President: Official Campaign Website | Join The Team | Biden for President</title>
<script src="https://use.typekit.net/lwk5jsx.js"></script><script>try{Typekit.load({ async: false });}catch(e){}</script>
<meta name="robots" content="noindex,follow">
<link rel="stylesheet" id="bexc-main-css" href="https://joebiden.com/wp-content/themes/bexc/css/main.css" type="text/css" media="all">
<link rel="canonical" href="https://go.joebiden.com/page/s/join_the_team">
<link rel="stylesheet" href="/page/static/20201019/skins/bsd-light/signup/frontend.css" type="text/css">
<script src="/page/static/20201019/ext/jquery/jquery-1.4.1.min.js" type="text/javascript"></script><script type="text/javascript">!window.jQuery && document.write(unescape(\'%3Cscript src="/ext/jquery/jquery-1.4.1.min.js"%3E%3C/script%3E\'))</script><script src="/page/static/20201019/ext/jquery/cookie/jquery.cookie.min.js" type="text/javascript"></script><script src="/modules/spud/js/Spud.js.php" type="text/javascript"></script><script src="/page/static/20201019/javascript/Core/form/gdprValidator.js" type="text/javascript"></script><script type="text/javascript">window.bQuery = jQuery.noConflict(true);</script>
<link rel="stylesheet" href="/page/static/20201019/css/jquery_ui_reset.css" type="text/css">
<script src="/page/static/20201019/javascript/bsd.js" type="text/javascript"></script><script src="/page/static/20201019/utils/locale/javascript/locale.class.js" type="text/javascript"></script><script src="/page/static/20201019/ext/yui/build/yahoo-dom-event/yahoo-dom-event.js" type="text/javascript"></script><script src="/page/static/20201019/modules/signup/javascript/locale.js" type="text/javascript"></script><script src="/page/static/20201019/modules/signup/javascript/onsubmit.js" type="text/javascript"></script><script src="/page/static/20201019/utils/ajax/ajax.class.js" type="text/javascript"></script><script src="/page/static/20201019/ext/jquery/mailcheck/jquery.mailcheck.js" type="text/javascript"></script><script type="text/javascript">\n\n(function(){\n function setcookie(name,value,days,domain) {\n var expires = days ? "; expires=" + (new Date(days*864E5 + (new Date()).getTime())).toGMTString() :"";\n document.cookie = name+"="+value+expires+"; path=/; domain="+domain;\n document.cookie = name+"="+value+expires+"; path=/";\n }\n setcookie("source", "website-joinpage", 7, "americanpossibilities.org");\n}());\n</script>
</head>
<body class="page-bsd language-en">
\r\n <!-- Google Tag Manager (noscript) -->\r\n
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M96J785" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
\r\n <!-- End Google Tag Manager (noscript) -->\r\n\r\n <a class="skip-link screen-reader-text" href="#main-content">Skip to content</a>\r\n\r\n
<div class="bsd-eyebrow">
\r\n
<div class="left">Return to joebiden.com</div>
\r\n
</div>
\r\n\r\n
<div class="site-header-wrapper">
\r\n
<header id="site-header" class="clearfix">
<div class="site-title">
\r\n
<a href="https://joebiden.com/" rel="home">
\r\n
<div class="element-invisible">Joe Biden for President 2020: Official Campaign Website</div>
\r\n <img src="https://joebiden.com/wp-content/themes/bexc/img/logo.svg" width="135" height="56" alt="Logo for Joe Biden for President">
</a>
\r\n
</div>
\r\n Donate\r\n
</header>
<!-- #site-header -->
</div>
\r\n\r\n
<div id="main-content">
\r\n
<main id="main">
<article class="view-page post-3 page type-page status-publish hentry">
<div class="entry-content">
\r\n\r\n
<style>\r\n \r\n.type-page.view-page .entry-content {\r\n font: 400 20px/27px \'brother-1816\', sans-serif;\r\n max-width: 600px;\r\n margin: -33px 0px 0px 75px;\r\n \r\n}\r\n#media screen and (max-width: 1000px) {\r\nbody {\r\n background: #ffffff;\r\n}\r\n\r\n.type-page.view-page .entry-content {\r\n max-width: 800px;\r\n margin: 20px auto 0 auto;\r\n} \r\n\r\n.type-page.view-page {\r\n \r\n border-bottom: 0px solid #D7D7D7 !important;\r\n}\r\n\r\n#main-content {\r\n padding-top: 20px;\r\n}\r\n\r\n}\r\n</style>
<!-- Content here -->
<div id="signupheader"></div>
<span class="signuperror">PLEASE CORRECT THE PROBLEMS MARKED BELOW</span><br>
<form name="signup" class="bsd-signup-21" action="/page/sp/join_the_team" method="post" id="signup">
\n
<table id="signuptable">
<tr>
<td>
\n
<table width="100%">
<td valign="top">
\n
<div class="fieldset" id="bsd-field-email">
\n
<div class="label"><label class="field">Email<span class="required">*</span></label></div>
\n
<div class="input"><input type="email" class="text" size="48" id="email" name="email"></div>
</div>
\n
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<td valign="top">
\n
<div class="fieldset" id="bsd-field-firstname">
\n
<div class="label"><label class="field">First Name</label></div>
\n
<div class="input"><input size="16" id="firstname" name="firstname" type="text"></div>
</div>
\n
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<td valign="top">
\n
<div class="fieldset" id="bsd-field-lastname">
\n
<div class="label"><label class="field">Last Name</label></div>
\n
<div class="input"><input size="25" id="lastname" name="lastname" type="text"></div>
</div>
\n
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%"></table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<td valign="top">
\n
<div class="fieldset" id="bsd-field-zip">
\n
<div class="label"><label class="field">Zip Code<span class="required">*</span></label></div>
\n
<div class="input"><input size="8" id="zip" name="zip" type="text"></div>
</div>
\n
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<td valign="top">
\n
<div class="fieldset" id="bsd-field-mobile">
\n
<div class="label"><label class="field">Mobile Phone (Optional)</label></div>
\n
<div class="input"><input type="tel" class="text" size="15" id="mobile" name="mobile"></div>
</div>
\n
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<td valign="top">
\n
<div class="fieldset" id="bsd-field-custom-1572-group">
\n
<div class="label"><label class="field">Volunteer</label></div>
\n
<div class="input"><input id="custom-1572_0" class="custom-1572" name="__custom-1572[0]" type="checkbox" value="1" onclick="if (this.checked) { this.form['custom-1572[0]'].value='Sign up for volunteer updates'; }else { this.form['custom-1572[0]'].value=''; } "><label for="custom-1572_0">Sign up for volunteer updates<br></label><input type="hidden" name="custom-1572[0]" value=""></div>
</div>
\n
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<div style="display: none"><label for="best-contact-time">Please leave this field blank:</label> <input id="best-contact-time" name="best-contact-time" type="text"></div>
<td valign="top">
\n
<div class="fieldset" id="bsd-field-submit-btn">
\n
<div class="label"><label class="field"></label></div>
\n
<div class="input"><input name="submit-btn" value="Submit Form" type="submit" id="submit_button"></div>
</div>
\n
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td id="required_note"><span class="required">*</span><span style="font-size: 80%;"> denotes required field</span></td>
</tr>
<input name="country" type="hidden" value="US"><input name="redirect_url" type="hidden" value=""><input id="_guid" name="_guid" type="hidden" value="">
</table>
</td>
\n
</tr>
</table>
</form>
<div id="signupfooter"></div>
<script type="text/javascript">\n bQuery(\'#email\').blur(\n function() {\n \n bQuery(this).mailcheck({\n domains: ["aol.com","att.net","bellsouth.net","charter.net","comcast.net","cox.net","earthlink.net","gmail.com","hotmail.com","icloud.com","live.com","mac.com","me.com","msn.com","optonline.net","outlook.com","sbcglobal.net","verizon.net","yahoo.com","ymail.com"],\n \n suggested: function(element, suggestion) {\n bQuery(element).parents(\'div.fieldset\').children(\'.bsd-mailcheck\').remove();\n\n bQuery(element).parents(\'div.fieldset\').append(\n \'<span class="error bsd-mailcheck">Did you mean \' +\n \'<a class="bsd-mailcheck-fix-link" href="#">\' +\n suggestion.domain + \'<\' + \'/a>?<\' + \'/span>\');\n\n bQuery(element).parents(\'div.fieldset\').find(".bsd-mailcheck-fix-link").click(\n function() {\n bQuery(element).val(suggestion.address + \'#\' + suggestion.domain);\n bQuery(element).parents(\'div.fieldset\').children(\'.bsd-mailcheck\').remove();\n });\n },\n empty: function(element) {\n bQuery(element).parents(\'div.fieldset\').children(\'.bsd-mailcheck\').remove();\n }\n });\n\n });\n</script>
<div id="fb-root"></div>
<!-- End Content -->\r\n
</div>
\r\n
</article>
</main>
<!-- #main -->
</div>
<!-- #main-content -->\r\n
<footer id="site-footer">
<div class="disclaimer">Paid for by Biden for President.</div>
<br>
<p>Support our presidential campaign to elect Joe Biden by signing up to volunteer or making a donation.</p>
\r\n\r\n
<nav id="nav-footer">
<ul class="menu">
<li>Blue State Digital Privacy Policy\r\n </li>
<li>© Copyright 2019. All rights reserved.</li>
\r\n
</ul>
</nav>
</footer>
<!-- #site-footer -->
</body>
</html>
'
It says "PLEASE CORRECT THE PROBLEMS BELOW"

In the code you are sending the POST request to the sign-up page which would'nt make a difference because the sign-up sends the input details to the page which actually adds the information to the list.
Here that page is identified in the action details of the form
action=/page/sp/join_the_team

Related

Web login using python or wget (JavaScript Challenge/response)

i am newbie with web scrapy and login. I need to login to an UPS to read information via Python or wget not matter which.
I tried to do it with wget:
wget --no-check-certificate --keep-session-cookies --post-data
'Username=admin&Password=admin' https://192.168.50.2/delta/login
But always get a web page with the error "Challenge not found"
Do you know any way to gets login in using challenge+response?
Here are the login page source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0035)https://192.168.50.2/home.asp -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Web Server Login</title>
<meta http-equiv="X-UA-Compatible" content="IE=9,8,7,6,5">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<!--<base target="_top">--><base href="." target="_top">
<link rel="stylesheet" href="./Web Server Login_files/template.css" type="text/css">
<script language="javascript" src="./Web Server Login_files/js.js.download"></script><script data-dapp-detection="">
(function() {
let alreadyInsertedMetaTag = false
function __insertDappDetected() {
if (!alreadyInsertedMetaTag) {
const meta = document.createElement('meta')
meta.name = 'dapp-detected'
document.head.appendChild(meta)
alreadyInsertedMetaTag = true
}
}
if (window.hasOwnProperty('web3')) {
// Note a closure can't be used for this var because some sites like
// www.wnyc.org do a second script execution via eval for some reason.
window.__disableDappDetectionInsertion = true
// Likely oldWeb3 is undefined and it has a property only because
// we defined it. Some sites like wnyc.org are evaling all scripts
// that exist again, so this is protection against multiple calls.
if (window.web3 === undefined) {
return
}
__insertDappDetected()
} else {
var oldWeb3 = window.web3
Object.defineProperty(window, 'web3', {
configurable: true,
set: function (val) {
if (!window.__disableDappDetectionInsertion)
__insertDappDetected()
oldWeb3 = val
},
get: function () {
if (!window.__disableDappDetectionInsertion)
__insertDappDetected()
return oldWeb3
}
})
}
})()</script><script type="text/javascript" src="./Web Server Login_files/jquery-1.4.4.pack.js.download"></script>
<script language="javascript" src="./Web Server Login_files/md5.js.download"></script>
<script language="JavaScript">
<!--
function calcResponse() {
str = document.login.Username.value +
document.login.Password.value +
document.login.Challenge.value;
document.login.Response.value = hex_md5(str);
if(1)
document.login.Password.value = "";
document.login.Challenge.value = "";
}
var logoix = "1";
var lang_support = "1111000000000000";
var odmtag = "0";
function Initialize(flag_Submit)
{
document.login.Username.focus();
if(flag_Submit) {
document.login.Submitbtn.click();
}
chklogo(logoix,'dlogos')
if(odmtag == "0")
{
document.getElementById('footnote').style.display="block"
document.getElementById('tabtitle').className="tabtl"
document.getElementById('logintitle').className="logintl"
}
}
--></script>
</head>
<body style="display: block;" onload="pageload();loadjs('/java/langs.js');setTimeout('Initialize()',10);">
<div style="display:none" id="currlang">0</div>
<form name="login" action="https://192.168.50.2/delta/login" method="post">
<center>
<div id="dslogin">
<p> </p>
<p> </p>
<div class="sidebox">
<h3> </h3>
<div class="sb">
<table cellpadding="0" cellspacing="0" border="0" width="480">
<tbody><tr><th colspan="3" id="tabtitle" class="tabtl"><div id="logintitle" class="logintl">UPSentry 2012</div></th></tr>
<tr><td colspan="3" style="padding-right:-6px;" valign="top">
<table cellpadding="8" cellspacing="8" border="0" height="100%" width="100%" class="loginfield">
<tbody><tr><td colspan="2"><img src="./Web Server Login_files/sp.gif" width="1" height="3"></td></tr>
<tr>
<td class="logintext"><span id="#2">User Name</span> : </td>
<td align="left"><input type="text" name="Username" value="" size="24" maxlength="32" style="font-size: 12px; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAAAXNSR0IArs4c6QAAAUBJREFUOBGVVE2ORUAQLvIS4gwzEysHkHgnkMiEc4zEJXCMNwtWTmDh3UGcYoaFhZUFCzFVnu4wIaiE+vvq6+6qTgthGH6O4/jA7x1OiCAIPwj7CoLgSXDxSjEVzAt9k01CBKdWfsFf/2WNuEwc2YqigKZpK9glAlVVwTTNbQJZlnlCkiTAZnF/mePB2biRdhwHdF2HJEmgaRrwPA+qqoI4jle5/8XkXzrCFoHg+/5ICdpm13UTho7Q9/0WnsfwiL/ouHwHrJgQR8WEwVG+oXpMPaDAkdzvd7AsC8qyhCiKJjiRnCKwbRsMw9hcQ5zv9maSBeu6hjRNYRgGFuKaCNwjkjzPoSiK1d1gDDecQobOBwswzabD/D3Np7AHOIrvNpHmPI+Kc2RZBm3bcp8wuwSIot7QQ0PznoR6wYSK0Xb/AGVLcWwc7Ng3AAAAAElFTkSuQmCC"); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%;" autocomplete="off"></td>
</tr>
<tr>
<td class="logintext"><span id="#3">Password</span> : </td>
<td align="left"><input type="password" name="Password" value="" size="24" maxlength="32" style="font-size: 12px; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAAAXNSR0IArs4c6QAAAUBJREFUOBGVVE2ORUAQLvIS4gwzEysHkHgnkMiEc4zEJXCMNwtWTmDh3UGcYoaFhZUFCzFVnu4wIaiE+vvq6+6qTgthGH6O4/jA7x1OiCAIPwj7CoLgSXDxSjEVzAt9k01CBKdWfsFf/2WNuEwc2YqigKZpK9glAlVVwTTNbQJZlnlCkiTAZnF/mePB2biRdhwHdF2HJEmgaRrwPA+qqoI4jle5/8XkXzrCFoHg+/5ICdpm13UTho7Q9/0WnsfwiL/ouHwHrJgQR8WEwVG+oXpMPaDAkdzvd7AsC8qyhCiKJjiRnCKwbRsMw9hcQ5zv9maSBeu6hjRNYRgGFuKaCNwjkjzPoSiK1d1gDDecQobOBwswzabD/D3Np7AHOIrvNpHmPI+Kc2RZBm3bcp8wuwSIot7QQ0PznoR6wYSK0Xb/AGVLcWwc7Ng3AAAAAElFTkSuQmCC"); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%;" autocomplete="off"></td>
</tr>
<tr><td> </td>
<td align="left"><input class="okbutn" onclick="calcResponse()" id="#4" type="Submit" name="Submitbtn" value=" OK "></td></tr>
</tbody></table>
</td>
</tr>
<tr>
<td colspan="3" class="logindevip"><span id="#5">Site IP</span>: 192.168.50.2</td>
</tr>
</tbody></table>
</div>
</div>
<input type="hidden" name="Challenge" value="f1e0....">
<input type="hidden" name="Response" value="">
<div id="footnote" style="display: block;">
<span id="#6">Copyright ©, All rights reserved.</span>
</div>
</div>
</center>
</form>
</body>
</html>
Regards!

Python scraping when site redirects to a new session

I am attempting to get data from a website that requires being in a certain location or to log in. My problem is that it seems to redirect to a new session that I am unable to programmatically access with Python. The following is how I tried to access it...
payload = {
'user' : 'myusername',
'pass': 'mypassword'
}
session = requests.session()
r = session.post("http://apps.webofknowledge.com/WOS_CitedReferenceSearch_input.do?SID=1DtxhgpRsI16gPP7tRC&product=WOS&search_mode=CitedReferenceSearch",
data=payload)
print(r.text)
which results in the following output that indicates the redirect is not being properly captured...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><!-- !DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN" -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href='http://login.webofknowledge.com/error/WOK5/WoKcommon.css' type="text/css" />
<link rel="stylesheet" href='http://login.webofknowledge.com/error/WOK5/main.css' type="text/css" />
<script language="javascript" src="http://login.webofknowledge.com/error/WOK5/jquery.js"></script>
<script language="javascript" src="http://login.webofknowledge.com/error/WOK5/main.js"></script>
<title>Web of Science - Starting New Session...</title>
<script>
function autoredirect() {
var s = "true";
document.cookie = "SID=1; expires=15/02/2000 00:00:00; domain=www.webofknowledge.com";
if (false == s)
{
setTimeout("this.form.submit()", null);
}
else
{
setTimeout("top.location.href='http://www.webofknowledge.com?'", null);
}
}
</script>
</head>
<body id="WoKerror" onload="javascript:autoredirect()">
<form action='http://www.webofknowledge.com'>
<div class="main-container">
<div class="navBar clearfix">
<ul class="userCabinet nav-list">
<li class="nav-item">
<a title="" class="nav-link" href="javascript: void(0)">English <i class="icon-arrow"></i></a>
<ul class="subnav">
<li class="subnav-item">
<a class="subnav-link" title="简体中文" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=zh_CN"> 简体中文</a>
</li>
<li class="subnav-item">
<a class="subnav-link" title="繁體中文" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=zh_TW"> 繁體中文</a>
</li>
<li class="subnav-item language-active-option">
<a class="subnav-link" title="English" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=en_US"> English</a>
</li>
<li class="subnav-item">
<a class="subnav-link" title="日本語" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=ja"> 日本語</a>
</li>
<li class="subnav-item">
<a class="subnav-link" title="한국어" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=ko_KR"> 한국어</a>
</li>
<li class="subnav-item">
<a class="subnav-link" title="Português" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=pt_BR"> Português</a>
</li>
<li class="subnav-item">
<a class="subnav-link" title="Español" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=es_LA"> Español</a>
</li>
<li class="subnav-item">
<a class="subnav-link" title="Pусский" href="http://login.webofknowledge.com/error/Error?DestApp=WOS&SID=1DtxhgpRsI16gPP7tRC&Error=Server.sessionNotFound&locale=ru_RU"> Pусский</a>
</li>
</ul>
</li>
</ul>
</div>
<div class="logoBar">
<h1 class="titleh1"> <span title="Web of Science">Web of Science</span> </h1>
<span><img alt="Clarivate Analytics" title="Clarivate Analytics" src="http://login.webofknowledge.com/error/WOK5/images/trlogo.png" /></span>
</div>
<!-- Begin : Module Title Shell -->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="NEWleftOuterEdge"><img src="http://login.webofknowledge.com/error/WOK5/images/spacer.gif" class="NEWleftOuterEdge" width="8"></td>
<td class="NEWwokErrorContainer">
<div class="NEWpageTitle"><H1>Thank you for using Web of Science</H1></div>
</td>
<td class="NEWrightOuterEdge"><img src="http://login.webofknowledge.com/error/WOK5/images/spacer.gif" class="NEWrightOuterEdge"></td>
</tr>
</tbody>
</table>
<!-- End : Module Title Shell -->
<!-- Begin : WoK Error Shell -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" valign="top">
<tr>
<td class="NEWleftOuterEdge"><img src="http://login.webofknowledge.com/error/WOK5/images/spacer.gif" width="8" class="NEWleftOuterEdge" /></td>
<td class="NEWwokErrorContainer SignInLeftColumn ">
<!-- Begin : Error -->
<h2>STARTING A NEW SESSION...</h2>
<p>
<p>If a new session is not started automatically in a few seconds, click establish a new session.
<!-- End : Error --></td>
<td class="NEWrightOuterEdge"><img src="http://login.webofknowledge.com/error/WOK5/images/spacer.gif" class="NEWrightOuterEdge" /></td>
</tr>
</table>
<!-- End : WoK Error Shell -->
</form>
<div id="skip-to-footer" class="footer">
<div class="footerContent">
<ul>
<li><span>© 2017</span> <a id="TRcopyright" title="Clarivate Analytics" href="http://clarivate.com" name="Clarivate Analytics" target="_new"> Clarivate Analytics</a></li>
<li><a id="TRpolicy" title="Terms of Use" href="http://wokinfo.com/terms" name="Terms of Use" target="_new"> Terms of Use</a></li>
<li><a id="TRprivacy" title="Privacy Policy" href="http://ip-science.thomsonreuters.com/privacy" name="Privacy Policy" target="_new"> Privacy Policy</a></li>
<li><a id="TRfeedback" title="Feedback" href="http://science.thomsonreuters.com/info/wokfeedback" name="Feedback" target="_new"> Feedback</a></li>
</ul>
</div>
</div>
</body></html>
I have tried first sending a post request, then sending a get request to the url that it redirects to when I am doing the same operation in my browser while passing in the cookies from the post request, but I am getting an empty array for my cookies when I call r.cookies , so I end up getting the same HTML output as shown above. The issue seems to be that I cannot redirect through Python into the new session the website initiates.

How to switch to frame source in selenium

I want to click an frame source's radio button, but it doesn't work. I think, frame source doesn't have iframe id or name.
my code is this.
import time
from selenium import webdriver
Url='https://www.youtube.com/watch?v=eIStvhR347g'
driver = webdriver.Firefox()
driver.get('https://video-download.online')
driver.find_element_by_id("link").send_keys(Url)
driver.find_element_by_id("submit").click()
time.sleep(5)
#this part is problems... don't working
driver.switch_to_frame(driver.find_element_by_xpath('//iframe'))
driver.find_elements_by_xpath("//*[#type='radio']")[0].click()
driver.find_element_by_xpath(".//button[contains(text(),'Proceed')]").click()
html source is this.
<html>
<head>
<meta charset="utf-8"/>
...
<script>
if (top.location !== location) {
top.location = self.location;
}
if (location.host !== 'video-download.online' && location.host !== 'beta.video-download.online') {
eval("location.href=''+'//'+'video-download.online';");
}
</script>
<meta name="msapplication-tap-highlight" content="no"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<meta name="author" content="Luca Steeb"/>
<meta name="theme-color" content="#008679"/>
<meta name="description" content="Download from this uploaded.net premium link generator with highspeed. For free."/>
<meta property="og:title" content="Video-Download.online"/>
<meta property="og:description" content="Download videos, mp3s and playlists from 1979 sites - for free."/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="video-download.online"/>
<meta property="fb:page_id" content="1143492155680932"/>
<meta property="og:image" content="//video-download.online/img/logo.jpg"/>
<link rel="shortcut icon" href="/favicon.ico?1"/>
<link rel="icon" sizes="192x192" href="/img/logo_small.jpg"/>
<link rel="apple-touch-icon" href="/img/apple-touch-icon.png"/>
<link rel="search" type="application/opensearchdescription+xml" title="Video-Download.online" href="/opensearch.xml"/>
<title>
Online Video Download
</title>
<meta name="robots" content="noindex, nofollow"/>
<link rel="stylesheet" href="/css/bt.css"/>
<link rel="stylesheet" href="/css/style.css"/>
<noscript><iframe height=0 src="//www.googletagmanager.com/ns.html?id=GTM-TWMNRP"style=display:none;visibility:hidden width=0></iframe></noscript><script>!function(e,t,a,n,r){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var g=t.getElementsByTagName(a)[0],m=t.createElement(a),s="dataLayer"!=n?"&l="+n:"";m.async=!0,m.src="//www.googletagmanager.com/gtm.js?id="+r+s,g.parentNode.insertBefore(m,g)}(window,document,"script","dataLayer","GTM-TWMNRP")</script>
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-54289597-5','auto');ga('send','pageview');</script>
<script>function send(action) { ga('send', 'event', 'button', 'click', 'download-' + action) }</script>
<script async src="/js/jquery.js"></script>
<script>function _(n,i){i?window[n]?i():setTimeout(function(){_(n,i)},100):window.jQuery?window.jQuery(document).ready(function(){n(window.jQuery)}):setTimeout(function(){_(n)},100)}</script>
</head>
<body>
<header class="navbar navbar-info navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle no-waves" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="nav-brand">
<a class="navbar-brand" href="/">
<img class="logo" src="/img/logo.svg" alt=""/>
<div class="parent">
Video-Download<small>.online</small>
<br/>
<span class="small-text">1979 sites officially supported</span>
<span id="changelog"></span>
</div>
<span class="clear"></span>
</a>
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<div class="social">
<div class="fb-like fb-nav" data-href="https://www.facebook.com/VideoDownload.online"
data-layout="button_count" data-action="like" data-show-faces="false" data-share="true">
</div>
</div>
<div class="social-close" title="Hide all social buttons">×</div>
<li class=" ">
<a href="/">
Home
</a>
</li>
<li class=" ">
<a href="/sites">
Sites
</a>
</li>
<li class=" ">
<a href="/contact">
Contact
</a>
</li>
<!--html.navItem('/app', 'Mobile App')-->
</ul>
</div>
</div>
</header>
<noscript class="fixed">
<div class="container">Please enable javascript. Video Download and almost all other sites don't work properly
without it.
</div>
</noscript>
<div id="alert" class="alert alert-fixed alert-dismissible m-t-15 hidden">
<div class="container relative">
<span id="alertText"></span>
<span class="close-alert" onclick="_(function() { $('#alert').remove();$('body').removeClass('alert-showing') })" title="close">×</span>
</div>
</div>
<main class="container">
<div>
<h1>Legal</h1>
<div style="width: 50%;" class="center">
</div>
</main>
<script src="/sweetalert/sweetalert.js"></script>
<link rel="stylesheet" href="/sweetalert/sweetalert.css">
<script src="/waves/waves.min.js"></script>
<script src="/js/dropdown.js"></script>
<script src="/js/main.js"></script>
<script src="/js/bootstrap.js"></script>
<script type="text/javascript">/* <![CDATA[ */(function(d,s,a,i,j,r,l,m,t){try{l=d.getElementsByTagName('a');t=d.createElement('textarea');for(i=0;l.length-i;i++){try{a=l[i].href;s=a.indexOf('/cdn-cgi/l/email-protection');m=a.length;if(a&&s>-1&&m>28){j=28+s;s='';if(j<m){r='0x'+a.substr(j,2)|0;for(j+=2;j<m&&a.charAt(j)!='X';j+=2)s+='%'+('0'+('0x'+a.substr(j,2)^r).toString(16)).slice(-2);j++;s=decodeURIComponent(s)+a.substr(j,m-j)}t.innerHTML=s.replace(/</g,'<').replace(/>/g,'>');l[i].href='mailto:'+t.value}}catch(e){}}}catch(e){}})(document);/* ]]> */</script></body>
</html>
frame source is this.
<html>
<head>
<meta charset="utf-8"/>
<meta name="robots" content="noindex, nofollow"/>
...
<link rel="stylesheet" href="/css/bt.css"/>
<link rel="stylesheet" href="/css/style.css"/>
<script src="/js/jquery.js"></script>
<style>body{margin:0!important;}tr{clear:both;cursor:pointer;}td{padding:0 20px 0 0;white-space:nowrap;}.radio{margin-top:5px;margin-bottom:5px;}.small{padding:0;font-size:85%;}#media (max-width: 319px) {table{font-size:12px;}}#media (max-width: 480px) {td{padding:0 5px 0 0;}.small{font-size:50%;}}</style>
</head>
<body>
<form id="format" method="post">
<input name="id" type="hidden" value="isxklqy5blw9of7"/>
<table>
<tr>
<td class="small">
<div class="">
<div class="radio " id="undefined-wrapper">
<label class="text-capitalize" for="undefined">
<input id="undefined" name="format" type="radio" value="undefined" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>I don't care</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td class="small">
<div class="">
<div class="radio " id="160-wrapper">
<label class="text-capitalize" for="160">
<input id="160" name="format" type="radio" value="160" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>256x144</td>
<td></td>
<td>
30 FPS
</td>
<td>23.2 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="133-wrapper">
<label class="text-capitalize" for="133">
<input id="133" name="format" type="radio" value="133" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>426x240</td>
<td></td>
<td>
30 FPS
</td>
<td>51.2 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="134-wrapper">
<label class="text-capitalize" for="134">
<input id="134" name="format" type="radio" value="134" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>640x360</td>
<td></td>
<td>
30 FPS
</td>
<td>65.4 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="135-wrapper">
<label class="text-capitalize" for="135">
<input id="135" name="format" type="radio" value="135" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>854x480</td>
<td></td>
<td>
30 FPS
</td>
<td>138.0 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="136-wrapper">
<label class="text-capitalize" for="136">
<input id="136" name="format" type="radio" value="136" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1280x720</td>
<td>HD</td>
<td>
30 FPS
</td>
<td>272.2 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="298-wrapper">
<label class="text-capitalize" for="298">
<input id="298" name="format" type="radio" value="298" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1280x720</td>
<td>HD</td>
<td>
60 FPS
</td>
<td>385.0 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="137-wrapper">
<label class="text-capitalize" for="137">
<input id="137" name="format" type="radio" value="137" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1920x1080</td>
<td>Full HD</td>
<td>
30 FPS
</td>
<td>535.0 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="299-wrapper">
<label class="text-capitalize" for="299">
<input id="299" name="format" type="radio" value="299" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1920x1080</td>
<td>Full HD</td>
<td>
60 FPS
</td>
<td>707.0 MB</td>
</tr>
</table>
<button class="btn center" type="submit">Proceed »</button>
</form>
</body>
<script>
$('tr').click(function() {
$(this).find('input').prop('checked', true);
});
</script>
<script src="/waves/waves.min.js"></script>
<script>
Waves.attach('.btn', ['waves-light']);
Waves.init();
</script>
html and frame sources are very long code, you can be check this full code.
html link
frame link
and I tried these codes, but don't work.
driver.switch_to_frame(driver.find_element_by_xpath('//iframe[contains(#name, "frame")]'))
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
driver.switch_to_frame(driver.find_element_by_xpath('//iframe'))
driver.switch_to_frame(0)
these iframe switching codes are any exception is nothing, but result is '[]'.
>>> driver.switch_to_frame(driver.find_element_by_xpath('//iframe'))
>>> driver.find_elements_by_xpath("//*[#type='radio']")
[]
>>> driver.find_elements_by_xpath("//*[#type='radio']")[0].click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
I needs your help. thanks you.
As I'm seeing on this url, there are multiple iframe present while, you are trying to switch to iframe with it's tagName only which will switch to first find iframe in order while your desired iframe is at 4th index which has no id and name attribute present, so you should try using CSS_SELECTOR with WebDriverWait using EC.frame_to_be_available_and_switch_to_it which will try to wait until desired iframe to be available and then switch to it as below working code :-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe:not([id]):not([name])")))
#now do your stuff to find element inside this iframe
#after doing all stuff inside this iframe switch back to default content for further steps
driver.switch_to_default_content()
Note:- You can also consider below one of these options to switch your desired iframe :-
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, ".//iframe[not(#name) and not(#id)]")))
or
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src*='selectFormat']")))
or using index :-
wait.until(EC.frame_to_be_available_and_switch_to_it(3))
The iframe is inside <noscript> tag, witch means the driver will see it only when javascript is disabled, as human user would. You can try to disable javascript when creating the driver
fp = webdriver.FirefoxProfile()
fp.set_preference("javascript.enabled", False)
driver = webdriver.Firefox(firefox_profile=fp)
I have created a simple method for switching the frames :
**public static void fn_SwitchToFrame(WebDriver driver, String frame){
if(frame.contains(">")){
String[] List = frame.split(">");
int ListSize = List.length;
for (int i=0; i<=(ListSize-1); i++){
driver.switchTo().frame(List[i]);
System.out.println("Switched to Frame :"+List[i]);
}
} else {
driver.switchTo().frame(frame);
System.out.println("Switched to Frame :"+frame);
}
}**
It works like this :
className.fn_SwitchToFrame(driver, "searchView>searchContent");
This will first switch to frame 'searchView' and then to 'searchContent'.
Hope this helps you.

how to click iframe using python selenium

I want to click an iframe's radio button, but it doesn't work.
my code is this.
import time
from selenium import webdriver
Url='https://www.youtube.com/watch?v=eIStvhR347g'
driver = webdriver.Firefox()
driver.get('https://video-download.online')
driver.find_element_by_id("link").send_keys(Url)
driver.find_element_by_id("submit").click()
time.sleep(5)
#this part is problems... don't working
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
driver.find_element_by_css_selector("136-wrapper").click()
driver.find_element_by_link_text("Proceed").click()
html source is this.
<html>
<head>
<meta charset="utf-8"/>
<script>
if (top.location !== location) {
top.location = self.location;
}
if (location.host !== 'video-download.online' && location.host !== 'beta.video-download.online') {
eval("location.href=''+'//'+'video-download.online';");
}
</script>
<meta name="msapplication-tap-highlight" content="no"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<meta name="author" content="Luca Steeb"/>
<meta name="theme-color" content="#008679"/>
<meta name="description" content="Download from this uploaded.net premium link generator with highspeed. For free."/>
<meta property="og:title" content="Video-Download.online"/>
<meta property="og:description" content="Download videos, mp3s and playlists from 1979 sites - for free."/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="video-download.online"/>
<meta property="fb:page_id" content="1143492155680932"/>
<meta property="og:image" content="//video-download.online/img/logo.jpg"/>
<link rel="shortcut icon" href="/favicon.ico?1"/>
<link rel="icon" sizes="192x192" href="/img/logo_small.jpg"/>
<link rel="apple-touch-icon" href="/img/apple-touch-icon.png"/>
<link rel="search" type="application/opensearchdescription+xml" title="Video-Download.online" href="/opensearch.xml"/>
<title>
Online Video Download
</title>
<meta name="robots" content="noindex, nofollow"/>
<link rel="stylesheet" href="/css/bt.css"/>
<link rel="stylesheet" href="/css/style.css"/>
<noscript><iframe height=0 src="//www.googletagmanager.com/ns.html?id=GTM-TWMNRP"style=display:none;visibility:hidden width=0></iframe></noscript><script>!function(e,t,a,n,r){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var g=t.getElementsByTagName(a)[0],m=t.createElement(a),s="dataLayer"!=n?"&l="+n:"";m.async=!0,m.src="//www.googletagmanager.com/gtm.js?id="+r+s,g.parentNode.insertBefore(m,g)}(window,document,"script","dataLayer","GTM-TWMNRP")</script>
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-54289597-5','auto');ga('send','pageview');</script>
<script>function send(action) { ga('send', 'event', 'button', 'click', 'download-' + action) }</script>
<script async src="/js/jquery.js"></script>
<script>function _(n,i){i?window[n]?i():setTimeout(function(){_(n,i)},100):window.jQuery?window.jQuery(document).ready(function(){n(window.jQuery)}):setTimeout(function(){_(n)},100)}</script>
</head>
<body>
<header class="navbar navbar-info navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle no-waves" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="nav-brand">
<a class="navbar-brand" href="/">
<img class="logo" src="/img/logo.svg" alt=""/>
<div class="parent">
Video-Download<small>.online</small>
<br/>
<span class="small-text">1979 sites officially supported</span>
<span id="changelog"></span>
</div>
<span class="clear"></span>
</a>
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<div class="social">
<div class="fb-like fb-nav" data-href="https://www.facebook.com/VideoDownload.online"
data-layout="button_count" data-action="like" data-show-faces="false" data-share="true">
</div>
</div>
<div class="social-close" title="Hide all social buttons">×</div>
<li class=" ">
<a href="/">
Home
</a>
</li>
<li class=" ">
<a href="/sites">
Sites
</a>
</li>
<li class=" ">
<a href="/contact">
Contact
</a>
</li>
<!--html.navItem('/app', 'Mobile App')-->
</ul>
</div>
</div>
</header>
<noscript class="fixed">
<div class="container">Please enable javascript. Video Download and almost all other sites don't work properly
without it.
</div>
</noscript>
<div id="alert" class="alert alert-fixed alert-dismissible m-t-15 hidden">
<div class="container relative">
<span id="alertText"></span>
<span class="close-alert" onclick="_(function() { $('#alert').remove();$('body').removeClass('alert-showing') })" title="close">×</span>
</div>
</div>
<main class="container">
<div>
<h1>Legal</h1>
<div style="width: 50%;" class="center">
</div>
</main>
<script src="/sweetalert/sweetalert.js"></script>
<link rel="stylesheet" href="/sweetalert/sweetalert.css">
<script src="/waves/waves.min.js"></script>
<script src="/js/dropdown.js"></script>
<script src="/js/main.js"></script>
<script src="/js/bootstrap.js"></script>
<script type="text/javascript">/* <![CDATA[ */(function(d,s,a,i,j,r,l,m,t){try{l=d.getElementsByTagName('a');t=d.createElement('textarea');for(i=0;l.length-i;i++){try{a=l[i].href;s=a.indexOf('/cdn-cgi/l/email-protection');m=a.length;if(a&&s>-1&&m>28){j=28+s;s='';if(j<m){r='0x'+a.substr(j,2)|0;for(j+=2;j<m&&a.charAt(j)!='X';j+=2)s+='%'+('0'+('0x'+a.substr(j,2)^r).toString(16)).slice(-2);j++;s=decodeURIComponent(s)+a.substr(j,m-j)}t.innerHTML=s.replace(/</g,'<').replace(/>/g,'>');l[i].href='mailto:'+t.value}}catch(e){}}}catch(e){}})(document);/* ]]> */</script></body>
</html>
frame source is this.
<html>
<head>
<meta charset="utf-8"/>
<meta name="robots" content="noindex, nofollow"/>
<link rel="stylesheet" href="/css/bt.css"/>
<link rel="stylesheet" href="/css/style.css"/>
<script src="/js/jquery.js"></script>
<style>body{margin:0!important;}tr{clear:both;cursor:pointer;}td{padding:0 20px 0 0;white-space:nowrap;}.radio{margin-top:5px;margin-bottom:5px;}.small{padding:0;font-size:85%;}#media (max-width: 319px) {table{font-size:12px;}}#media (max-width: 480px) {td{padding:0 5px 0 0;}.small{font-size:50%;}}</style>
</head>
<body>
<form id="format" method="post">
<input name="id" type="hidden" value="isxklqy5blw9of7"/>
<table>
<tr>
<td class="small">
<div class="">
<div class="radio " id="undefined-wrapper">
<label class="text-capitalize" for="undefined">
<input id="undefined" name="format" type="radio" value="undefined" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>I don't care</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td class="small">
<div class="">
<div class="radio " id="160-wrapper">
<label class="text-capitalize" for="160">
<input id="160" name="format" type="radio" value="160" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>256x144</td>
<td></td>
<td>
30 FPS
</td>
<td>23.2 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="133-wrapper">
<label class="text-capitalize" for="133">
<input id="133" name="format" type="radio" value="133" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>426x240</td>
<td></td>
<td>
30 FPS
</td>
<td>51.2 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="134-wrapper">
<label class="text-capitalize" for="134">
<input id="134" name="format" type="radio" value="134" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>640x360</td>
<td></td>
<td>
30 FPS
</td>
<td>65.4 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="135-wrapper">
<label class="text-capitalize" for="135">
<input id="135" name="format" type="radio" value="135" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>854x480</td>
<td></td>
<td>
30 FPS
</td>
<td>138.0 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="136-wrapper">
<label class="text-capitalize" for="136">
<input id="136" name="format" type="radio" value="136" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1280x720</td>
<td>HD</td>
<td>
30 FPS
</td>
<td>272.2 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="298-wrapper">
<label class="text-capitalize" for="298">
<input id="298" name="format" type="radio" value="298" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1280x720</td>
<td>HD</td>
<td>
60 FPS
</td>
<td>385.0 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="137-wrapper">
<label class="text-capitalize" for="137">
<input id="137" name="format" type="radio" value="137" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1920x1080</td>
<td>Full HD</td>
<td>
30 FPS
</td>
<td>535.0 MB</td>
</tr><tr>
<td class="small">
<div class="">
<div class="radio " id="299-wrapper">
<label class="text-capitalize" for="299">
<input id="299" name="format" type="radio" value="299" onchange="" undefined required />
<span class=circle></span><span class=check></span>
<span class="grey-text"></span>
</label>
</div>
</div>
</td>
<td>1920x1080</td>
<td>Full HD</td>
<td>
60 FPS
</td>
<td>707.0 MB</td>
</tr>
</table>
<button class="btn center" type="submit">Proceed »</button>
</form>
</body>
<script>
$('tr').click(function() {
$(this).find('input').prop('checked', true);
});
</script>
<script src="/waves/waves.min.js"></script>
<script>
Waves.attach('.btn', ['waves-light']);
Waves.init();
</script>
I tried these codes, but don't work.
driver.switch_to_frame(driver.find_element_by_xpath('//iframe[contains(#name, "frame")]'))
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
driver.switch_to_frame(driver.find_element_by_xpath('//iframe'))
driver.switch_to_frame(0)
these iframe switching codes are any exception is nothing, but result is '[]'.
>>> driver.switch_to_frame(driver.find_element_by_xpath('//iframe'))
>>> driver.find_elements_by_xpath("//*[#type='radio']")
[]
>>> driver.find_elements_by_xpath("//*[#type='radio']")[0].click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
thanks for your help
(Assuming provided HTML is correct) actually your both locator is wrong to locate radio button element as well as proceed button element.
driver.find_element_by_css_selector("136-wrapper").click()
Using css_selector id locator used with #, so correct css_selector with id should be #136-wrapper
But this locator will be locate to <div> element while you want <input id="136" name="format" type="radio" value="136" onchange="" undefined required /> element, so here you can locate radio button and click using find_element_by_id() as :-
driver.find_element_by_id("136").click()
driver.find_element_by_link_text("Proceed").click()
find_element_by_link_text() works to locate only <a> anchor element with text while you want to locate <button> element, so this locator wouldn't work.
To locate Proceed button you should try using find_element_by_xpath() as :-
driver.find_element_by_xpath(".//button[contains(text(),'Proceed')]").click()

How do I Login to A site using Python for scraping purposes

I'm relatively new to python and programming generally. I've tried to follow steps provided from similar questions here but My program is unable to successfully Log in. The latest code I got from How to scrape a website which requires login using python and beautifulsoup?
Below is my attempted code: and the response I get
import mechanize
import BeautifulSoup
import urllib2
import cookielib
cj = cookielib.CookieJar()
br = mechanize.Browser()
br.set_cookiejar(cj)
br.open("http://www.bbnplace.com/accounts_v2/?do=signin&service=prepaidsms&returnto=http%3A%2F%2Fsms.bbnplace.com%2Fsentdir.php")
br.select_form('blogin')
br.form['busername'] = 'my_username'
br.form['passwd'] = 'my_password'
response = br.submit()
print br.response().read()
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="keywords" content="bulksms, bulk sms, bulk sms gateway, cheap bulk sms, bulk sms provider, bulk sms to nigeria, send bulk sms, personalized bulk sms, bulk sms nigeria, best sms site in nigeria, nigerian bulks sms gateway, web to mobile sms" />
<meta http-equiv="description" content="Send bulk sms with personalized sender name to all GSM networks in Nigeria and over 800 networks in 160 countries. Nigeria's Best SMS Gateway." />
<title>BBN SMS Messenger: Retail Web to Mobile Bulk SMS Messaging Utility</title>
<link rel="stylesheet" href="http://www.bbnplace.com/accounts_v2/style/layout.css" type="text/css" media="screen" />
<script type="text/javascript" async src="http://www.bbnplace.com/accounts_v2/bbjs/un.js"></script>
<script type="text/javascript">var L;var C;var bw=0;var G;var eD;var am;var eE=0;var method;var url;var J;var be;var fp='';var eY='';var dW=0;var eH='dG';var eG;var action='sent';var bS=0;var eC='';var eW=new Number();var bP='';var ft='save';var host=document.domain=='localhost'?'localhost/smsmessenger/':'sms.bbnplace.com';var protocol='http';var fc;var eA=protocol+"://"+host+"/source/";var dR=0;var responseText;var response=new Array();var bs;var bV=new Number();var H;var request;var fl;var aB;var aQ;var aL=window.innerWidth;var ab=window.innerHeight;var ca=new Array();var aK=new Array();var cv=new Array();var bb=new Array();var dN=new Array();aB=document.getElementById('aD');var et=110;aQ=document.getElementById('bx');if(request=='gocheck'){ad();}function ak(v){var k=document.getElementById(v);k.style.visibility='hidden';k.style.height='0px';};function aE(v){var k=document.getElementById(v);k.style.visibility='inherit';k.style.height='auto';};function bJ(v,ba){var ids=new Array();var aw=new String();aw=ba;ids=aw.split(',');for(var i=0;i<ids.length;i++){ak(ids[i]);}ids='';aE(v);return;};function ay(bF,cF,dw,bH,bi,aq,bN,aA){be=bi;C=bH;G=aq;H=aA;J=dw;method=bF;url=cF;am=bN;L=bO();if(L){if(method=='post'){try{L.open(method,url,true);L.onreadystatechange=bg;L.setRequestHeader('Content-Type','application/x-www-form-urlencoded');L.setRequestHeader('Content-Length',J.length);L.setRequestHeader('Connection','close');L.send(J);}catch(e){alert("Error connecting to server: "+e.toString());}}else{try{J.length>1?aG=url+'?'+J:aG=url;L.open(method,aG,true);L.onreadystatechange=bg;L.send(null);}catch(e){alert("Could not connect to server: "+e.toString());}}}};function bg(){var d;if(C.length>0){d=document.getElementById(C);}if(L.readyState==4){if(L.status==200){try{var response=dO();if(C.length>0){d.style.visibility='hidden';}bw=0;}catch(e){d.innerHTML="Error reading server response: "+e.toString();}}else{if(C.length>0){if(L.status){d.innerHTML='Server Response: '+L.status+' - '+L.statusText;d.style.visibility='visible';}else{d.innerHTML='Connection to server failed. Retrying...';d.style.visibility='visible';bQ=setTimeout('bz()',5000);}}}}else{if(C.length>0){d.innerHTML='<img border="0" src="style/29.gif" align="absmiddle" /> <b>Loading...</b>';d.style.visibility='visible';ap=setTimeout('dK()',(be*1000));}}return response;};function dK(){if(L.readyState!=4){clearTimeout(ap);document.getElementById(C).innerHTML='Connection is too slow. Retrying...';bQ=setTimeout('bD()',5000);}};function bD(){clearTimeout(bQ);if(L.readyState!=4){L.abort();ay(method,url,J,C,be,G,H);}};function bz(){clearTimeout(bQ);if(!L.status){L.abort();ay(method,url,J,C,be,G,H);}};function df(){x=document.getElementById(C);x.style.visibility='hidden';};function dO(){var responseText,cp;var doctype=L.getResponseHeader('Content-Type').toString();var l=document.getElementById(G);if(H.length){var aJ=document.getElementById(H);}l.innerHTML='';response['type']=doctype;if(doctype=='text/plain'||doctype=='text/html'){responseText=L.responseText;if(responseText.substr(0,4)=='Err:'){l.innerHTML=responseText.substr(5);l.style.visibility='inherit';l.style.height='auto';if(responseText.substr(5)==''){if(bS>0){l.innerHTML='<span style="color:red;">'+bP+'</span>';}}}else if(responseText.substr(0,3)=='OK:'){var aH=responseText.substr(4);switch(request){case 'newpost':document.forms[request].es.value=aH;bs.innerHTML='Saved';eu();break;}}else{if(H.length){aJ.innerHTML=responseText;}else if(request=='gocheck'){l.innerHTML=responseText;y=document.forms.di;if(responseText=='available'){y.cf.value=1;y.ds.value=y.username.value;l.innerHTML='Available';l.style.fontWeight='bold';l.style.color='green';ad();}}else{if(responseText=='successful'){switch(request){case 'newRequest':bJ('h','h,j');break;}}else if(responseText=='denied'){bf=protocol+'://'+host+'/accounts';window.location=bf;}else{alert(responseText);}}}}};function bO(){try{L=new XMLHttpRequest();}catch(e){var aI=new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP');for(var i=0;i<aI.length&& !L;i++){try{L=new ActiveXObject(aI[i]);}catch(e){}}}if(!L){alert('Please Upgrade your web browser');}else{return L;}};function aN(){var x=document.forms['t'];request='newRequest';aq='V';var bp,ao,aW,az;bp=x.ag.value;ao=x.bI.value;aW=x.aR.value;dr=x.an.value;az=x.av.value;aZ='eml='+encodeURIComponent(ao)+'&f='+encodeURIComponent(bp)+'&p='+encodeURIComponent(aW)+'&m='+encodeURIComponent(az)+'&p2='+encodeURIComponent(dr);al=document.getElementById('V');al.style.visibility='hidden';al.style.height=0;dP='source/contact.php';ay('post',dP,aZ,'',30,'V','','');};function cu(){dJ();};function cl(){ce();};function bB(aX){var x=document.getElementById('bh');if(!x){var x=document.createElement('div');x.setAttribute('id','bh');x.style.backgroundColor='#000';x.style.top='0px';x.style.left='0px';x.style.position='fixed';x.style.zIndex=99999;x.style.opacity=0.5;}x.style.width=aL+'px';x.style.height=ab+'px';x.style.visibility='visible';document.body.appendChild(x);if(aX==null){var T=document.getElementById('t');T.style.visibility='visible';T.style.height='auto';T.style.position='fixed';T.style.left=(aL/2-250)+'px';T.style.width='500px';T.style.zIndex=10000001;bJ('j','h,j');}else{var T=document.getElementById('ax');T.style.visibility='visible';bV=aX;}};function ar(){var bE=document.getElementById('bh');bE.style.width='0px';bE.style.height='0px';bE.style.visibility='hidden';if(bV==0){ak('h');ak('j');ak('t');document.forms['t'].reset();}else{var T=document.getElementById('ax');T.style.visibility='hidden';bV=0;}};function cU(i){var aY=document.getElementById('bA');aY.innerHTML='<b>Message:</b><br />'+aK[i];aY.innerHTML+='<br /><br /><b>Broadcasted:</b> '+bb[i];document.getElementById('as').style.visibility='visible';ez(ca[i]);};function dA(){document.getElementById('as').style.visibility='hidden';document.getElementById('ae').innerHTML='';}</script>
</head>
<body><div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=174240488183";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script><div id="ppbd"></div><div id="ppbdc"></div><div id="logoholder"></div>
<div id="app_header">
<div id="line1_left"><img src="http://www.bbnplace.com/accounts_v2/style/smlogo.png" align="absmiddle" title="BBN SMS Messenger: Retail Web to Mobile Bulk SMS Messaging Utility" /></div>
<div id="line1_right">Hi Buddie! | Messaging Solutions | BBN </div>
</div>
<div id="cK" align="right"> </div><div id="workarea" align="center">
<div id="frm_right">
<div id="note_panel"><div align="left">
<!-- <div style="margin: 0 0 40px; font-size: 22px; line-height: 27px;">
manage your contacts • send sms to <b style="color: red;">groups</b>
• from personal computer and <b style="color: red;">mobile</b>
</div> -->
<div style="font-size: 28px; line-height: 35px; margin: 35px 0 0;">
Send bulk sms • <b style="color: red;">confidently!</b>
</div>
<div id="bslogin_nav">
<img alt="How to Recharge" src="style/cc_icon.png" align="absmiddle" />
<b>Learn How to Recharge</b> <img
alt="Bundles and Pricing" align="absmiddle" src="style/cog_icon.png" />
<b><a
href="http://www.bbnplace.com/documentation/?service=prepaidsms&article=networks&returnto="
target="_blank">See our Network Coverage</a></b>
</div>
<script type="text/javascript">function dJ(){var x=document.forms['aN'];var V=new Number(x.df.value);var v=new Number(0);if(isNaN(V)){document.getElementById("J").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("hBp").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("T").innerHTML="<span style='color: red;'>waiting...</span>";if(document.forms.F){document.forms.F.bJ.disabled=true;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML="<span style='color: red;'><strong>Please Enter a Numberic Value</strong></span>";}}if(V<50){document.getElementById("J").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("hBp").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("T").innerHTML="<span style='color: red;'>waiting...</span>";if(document.forms.F){document.forms.F.bJ.disabled=true;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML="<span style='color: red;'><strong>Please specify a minimum of 50</strong></span>";}}else if(V>=50&&V< 1000){document.getElementById("J").innerHTML="Teams & Groups";document.getElementById("hBp").innerHTML="NGN 3.50";v=V* 3.50;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Teams & Groups';document.forms.F.hBp.value= 3.50;document.forms.F.T.value=v;}}else if(V>= 1000 &&V< 10000){document.getElementById("J").innerHTML="Business Standard";document.getElementById("hBp").innerHTML="NGN 2.20";v=V* 2.20;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Business Standard';document.forms.F.hBp.value= 2.20;document.forms.F.T.value=v;}}else if(V>= 10000 &&V< 50000){document.getElementById("J").innerHTML="Business Professional";document.getElementById("hBp").innerHTML="NGN 2.00";v=V* 2.00;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Business Professional';document.forms.F.hBp.value= 2.00;document.forms.F.T.value=v;}}else if(V>= 50000){document.getElementById("J").innerHTML="Business Premium";document.getElementById("hBp").innerHTML="NGN 1.85";v=V* 1.85;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Business Premium';document.forms.F.hBp.value= 1.85;document.forms.F.T.value=v;}}} </script>
<div align="left" id="pricelist">
<div align="right"><div id="price_tag"><img src="http://www.bbnplace.com/accounts_v2/style/price_tag.png" align="top" /> Bundles & Pricing</div></div>
<form id="aN" name="aN" method="post" action="">
<div style="margin: 0 0 5px;">
<label for="select"></label> <b>Currency</b> <select
name="aD" id="aD" onchange="ck(this.value)" disabled="disabled">
<option value="ngn" selected="selected" >NGN</option>
<option value="usd" >USD</option>
<option value="eur" >EUR</option>
</select>
</div>
<div>
<table cellpadding="3" cellspacing="0" width="100%" id="price_tags">
<tr>
<th align="left">Bundle</th>
<th width="120" align="right">Min. Volume</th>
<th width="80" align="right">Unit Price</th>
</tr> <tr>
<td style="background-color: #FFF; white-space:nowrap; overflow:hidden; text-overflow: clip;">Teams & Groups</td>
<td align="right" style="background-color: #FFF;">50</td>
<td align="right" style="background-color: #FFF;">3.50</td>
</tr> <tr>
<td style="background-color: #FAFAFA; white-space:nowrap; overflow:hidden; text-overflow: clip;">Business Standard</td>
<td align="right" style="background-color: #FAFAFA;">1,000</td>
<td align="right" style="background-color: #FAFAFA;">2.20</td>
</tr> <tr>
<td style="background-color: #FFF; white-space:nowrap; overflow:hidden; text-overflow: clip;">Business Professional</td>
<td align="right" style="background-color: #FFF;">10,000</td>
<td align="right" style="background-color: #FFF;">2.00</td>
</tr> <tr>
<td style="background-color: #FAFAFA; white-space:nowrap; overflow:hidden; text-overflow: clip;">Business Premium</td>
<td align="right" style="background-color: #FAFAFA;">50,000</td>
<td align="right" style="background-color: #FAFAFA;">1.85</td>
</tr> </table>
</div>
<div style="margin: 30px 0;">
Specify sms volume in the space below to get pricing <br />
<div>
<table width="100%" border="0" cellpadding="2" cellspacing="0"
id="aH">
<tr>
<th width="80">Volume</th>
<th width="">Bundle</th>
<th width="80" align="right">Unit Price</th>
<th width="" align="right">Price</th>
</tr>
<tr>
<td bgcolor="#FEFEFE"><input name="df" type="text" value=""
size="10" maxlength="10" onkeyup="dJ()" /></td>
<td bgcolor="#FEFEFE"><div id="J">
<input name="J" type="hidden" id="J" value="" />
</div></td>
<td align="right"><div id="hBp">
<input name="hBp" type="hidden" id="hBp" value="" />
</div></td>
<td align="right"><div id="T"><a name="how_to_recharge"></a>
<input name="T" type="hidden" id="T" value="" />
</div></td>
</tr>
</table>
</div>
</div>
</form>
IMPORTANT: *<strong>Business Premium bundle</strong> is the only <span
style="color: red; font-weight: bold;">negotiable</span> bundle.
</div><div align="left" style="margin: 50px 0 0;">
<h2>How to Recharge</h2>
<p>Pay online with any Nigerian debit/credit card, or at any branch of the listed banks:</p>
<div>
<img alt="web payment" src="http://www.bbnplace.com/checkout/image/webpaymentgateways.gif" height="55" />
</div>
<div style="font-size: 14px;">
Account Name: <b>Browser Based Nigeria</b>
</div>
<div style="clear: both; width: 100%;">
<div id="bM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/zenith.jpeg"
alt="Zenith Bank" width="50" height="50" /><br />1012259075
</div>
<div id="bM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/gtblogo.gif"
alt="Guaranty Trust Bank" width="50" height="50" /><br />0008382123
</div>
<div id="bM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/diamondbank.jpg"
alt="Diamond Bank Plc" width="50" height="50" /><br />0010549507
</div>
<div id="ibM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/accessbank_logo.png"
alt="Access Bank Plc" height="30" style="padding: 5px 0;" /><br />0049632011</div>
</div>
</div></div></div>
<div id="form_pane">
<div id="form_panel"><div align="left" id="signup">
<form name="signup_init" method="post" onsubmit = "return false;" autocomplete="off">
<div align="right"><h2>Get Started!</h2></div>
<div id="signup_init_error_message"></div>
<div><b>Email</b></div>
<div>
<input name="new_user_email" type="email" id="new_user_email" onkeypress="quickSubmit(event, 'signup_init', 'signup_init_error_message')" title="Type Email" size="45" style="width:100%" />
<span style="display: none;">User Email</span>
</div>
<div>
<input type="hidden" name="validemail" value="0" />
<input type="hidden" name="bservice" value="prepaidsms" />
<input type="button" name="button2" id="aC" value="Sign Up" onclick="processFrm('signup_init', 'signup_init_error_message');" />
</div>
</form>
</div></div>
<div id="forms_seperator">OR</div>
<div id="form_panel"><div>
<form name="blogin" method="post" onsubmit="return false;" autocomplete="off">
<div align="right"> <h2>Login</h2> </div>
<div id="errormsg"></div>
<div align="left">Email<br />
<label for="username"></label>
<input type="email" name="busername" id="busername" class="frmfield" value="" onkeypress="quickSubmit(event, 'blogin', 'errormsg')" title="This should be your email" />
</div>
<div align="left">Password<br />
<input type="password" name="passwd" id="passwd" class="frmfield" value="" onkeypress="quickSubmit(event, 'blogin', 'errormsg')" />
</div>
<div>
<input type="hidden" name="bservice" id="bservice" value="prepaidsms" />
<input type="hidden" name="returnto" id="returnto" value="http://sms.bbnplace.com/sentdir.php" />
<input type="hidden" name="errordiv" id="errordiv" value="errormsg" />
<input type="hidden" name="ipaddress" id="ipaddress" value="41.58.242.131" />
</div>
<div align="left">
<label><input name="rememberme" type="checkbox" id="rememberme" value="1" /> Remember Me!</label>
<input type="button" name="button" id="button" class="K" value="Login" onclick="processFrm('blogin','errormsg')" />
</div>
<div style="padding: 5px 0;">Can't access my account</div>
</form>
</div></div>
<div style="margin: 18px 0;">
<div style="margin: 0 0 5px;">Join our social conversation</div>
<div class="fb-like" data-href="http://www.facebook.com/bbnsms"
data-send="false" data-layout="button_count" data-width="250"
data-show-faces="false"></div>
</div>
</div>
</div></div>
<div style="clear:both;"> </div><div id="statsbar"></div>
</div>
<div id="aj" align="center"></div>
<div align="center" id="bn">
<a href="//bs.bbnplace.com" title="Business Solutions">Business
Solutions</a> | Developers | Documentation
| Newsroom
| Blog | <a
href="//www.bbnplace.com?entry=contact" target="_blank">Contact
Us</a> <a href="//twitter.com/bbnplace" title="on Twitter"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/twitter.png" alt="on Twitter"
width="16" height="16" border="0" /></a> <a
href="//www.facebook.com/bbnplace" title="on Facebook"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/facebook.png" alt="on Facebook"
width="16" height="16" border="0" /></a> <a
href="//www.linkedin.com/groups?gid=4620527" title="at LinkedIn"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/linkedin.png" alt="at LinkedIn"
width="16" height="16" border="0" /></a> <a
href="//www.youtube.com/user/bbnplace" title="on Youtube"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/youtube.png" alt="on Youtube"
width="16" height="16" border="0" /></a> <a
href="//newsroom.bbnplace.com" title="at the Newsroom"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/radio.png" alt="Newsroom" width="16"
height="16" border="0" /></a>
<br /> Copyright © 2008 - 2016 <a
href="//www.bbnplace.com" title="Browser Based Network Ltd">Browser
Based Network Ltd</a>. <img src="//www.bbnplace.com/accounts_v2/style/ngr.png" align="absmiddle"
alt="Nigeria" /> Nigeria. All rights reserved.
<br />Terms of Service • Privacy Policy Statement
<br /> <b>Desktop | Mobile Edition
</b>
</div>
<div
style="float: right; position: fixed; z-index: 100000; top: 230px; right: 0px;">
<img src="//www.bbnplace.com/accounts_v2/style/feedback_button.png" onclick="bB()"
style="cursor: pointer;" />
</div><div id="t">
<div id="j">
<form name="t" action="return false;" method="post">
<input type="hidden" name="an" value="Mobile Messaging Solutions" />
<h1 style="color: #555;">Send Us Feedback</h1>
<div>If you notice something is not working properly or you have a
suggestions. We appreciate hearing from you</div>
<div id="V"></div>
<div>
<b>Full Name:</b><br /> <input type="text" name="ag"
style="width: 95%;" />
</div>
<div>
<b>Email:</b><br /> <input type="text" name="bI" style="width: 95%;" />
</div>
<div>
<b>Phone:</b> <i>(optional)</i><br /> <input type="text" name="aR"
style="width: 200px;" />
</div>
<div>
<b>Suggestion:</b><br />
<textarea name="av" rows="10"
style="width: 95%; min-width: 95%; max-width: 95%; height: 100px; max-height: 100px;"></textarea>
</div>
<div>
Read our <a href="http://docs.bbnplace.com/?article=privacy_policy"
target="_blank">Privacy Policy</a> statement
</div>
<div style="margin: 10px 0 0;">
<span id="aC" onclick="aN()">Submit Feedback</span> <span class="K"
onclick="ar()">Cancel</span>
</div>
</form>
</div>
<div id="h">
<div id="bv">
<img src="style/correct_marking.gif" align="absmiddle" /> Your
feedback has been received. Thank you for the time taken
</div>
<div style="margin: 50px 0 0;">
<span class="K" onclick="ar()">Close</span>
</div>
</div>
</div><div id="cs"><div style="text-align:center;white-space:nowrap;"> <div><img alt="Live chat" src="https://cbi.boldchat.com/aid/4518259610467392165/bc.cbi?cbdid=6794783422064795815" border="0"/></div></div></div></body>
</html>
You just need to post to the correct url, once successfully logged in you will be able to get whatever page you like, this is a working example using requests:
import requests
from bs4 import BeautifulSoup
post = "http://www.bbnplace.com/accounts_v2/source/loginp.php"
data = {"eml": "your_email",
"p": "your_pass"}
# use a Session to persist cookies.
with requests.Session() as s:
r = s.post(post, data=data) # log us in
print(r.content) # will output "successful" for correct login
r = s.get("http://sms.bbnplace.com/account.php") # get account page
soup = BeautifulSoup(r.content)
print(soup.title.text)

Categories