Extracting Data from a HTTP log file for a Specific string - search

Hi what I want to do is capture the web site details from a log file (see example below), only the data between the url= and the / is required.
The Text that I want will appear like :- url=http://rewards.ebay.com.au/
This will come from a file downloaded to the local computer.
So far my Linux skills have failed me, as there are very rusty.
2016:10:07-09:22:08 remote httpproxy[5492]: id="0001" severity="info" sys="SecureWeb" sub="http" name="http access" action="pass" method="GET" srcip="172.20.47.77" dstip="66.135.210.162" user="" group="" ad_domain="" statuscode="200" cached="0" profile="REF_DefaultHTTPProfile (Default Web Filter Profile)" filteraction="REF_DefaultHTTPCFFAction (Default content filter action)" size="528" request="0x176b8c00" url="http://rewards.ebay.com.au/ws/eBayISAPI.dll?GetRewardsInfo&item=112156322448&ShowCoupon=true&ShowVoucher=false&IsBidFlow=true&IsViewItem=true&item=112156322448&cguid=97fac6cc1530a629a7c13ed1f7ab0909&cb=jQuery17035599369188600694_1475803327599&_=1475803328055" referer="http://www.ebay.com.au/itm/1-6-SCALE-dragon-WW2-GERMAN-SS-OFFICERS-WHITE-PIPS-AND-DECORATIONS/112156322448?_trksid=p2060778.c100276.m3476&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20140813105702%26meid%3D29ba022992ea4bd783400dd10e50825f%26pid%3D100276%26rk%3D3%26rkt%3D4%26sd%3D112152394027" error="" authtime="0" dnstime="108071" cattime="261877" avscantime="0" fullreqtime="1123523" device="1" auth="0" ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" exceptions="" category="158" reputation="trusted" categoryname="Auctions/Classifieds" content-type="application/json" application="ebay" app-id="134"
2016:10:07-09:22:09 remote httpproxy[5492]: id="0001" severity="info" sys="SecureWeb" sub="http" name="http access" action="pass" method="GET" srcip="172.20.47.77" dstip="66.135.211.38" user="" group="" ad_domain="" statuscode="200" cached="0" profile="REF_DefaultHTTPProfile (Default Web Filter Profile)" filteraction="REF_DefaultHTTPCFFAction (Default content filter action)" size="5242" request="0x174b3800" url="http://srx.au.ebayrtm.com/rtm?RtmCmd&a=json&i=3Fw8hYwlfJGMGXyhg&g=97fabafb1530a63a3093c5c8ffd648ea&uf=1&c=1H4sIAAAAAAAAAFVSTW%2FiMBC98ytGWqmHVUo8Y8d2kKwqgtAibQIiqbhwIRBBqkIiSBalv35tsrtST%2FPxxm9m3vhHfupguW%2BBSUA9IZqwAF6T%2FJmpCWNADOWo4UwbMWqEIMNGDYbCEFmHGQy0VKFLocn7pvSifVvVF5hXx%2B5aeln1VXpI1WXsJavUm9XlDdK6hahpPvtRQ1oZJEKhSGDIAw%2BRMKBQSC20ZzlVwEhqjczjEimQTAZSCI80oUKulQVtb6VNXvc3D97qoqjK27ZjjOG3Sf7mkuqzanfXHp4gOvwuL62FBsTRBP%2FW2VcHO9cAIPtfIISxhqNyhqwkGFjLpUnLu3WkeohDQ1pKEyobokE2Zq5OmGf3LnRtJAtEyB2L1dCXkE2" referer="http://www.ebay.com.au/itm/1-6-SCALE-dragon-WW2-GERMAN-SS-OFFICERS-WHITE-PIPS-AND-DECORATIONS/112156322448?_trksid=p2060778.c100276.m3476&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20140813105702%26meid%3D29ba022992ea4bd783400dd10e50825f%26pid%3D100276%26rk%3D3%26rkt%3D4%26sd%3D112152394027" error="" authtime="0" dnstime="106880" cattime="271" avscantime="0" fullreqtime="1160152" device="1" auth="0" ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" exceptions="" category="158" reputation="neutral" categoryname="Auctions/Classifieds" content-type="application/x-javascript" application="ebay" app-id="134"
2016:10:07-09:22:09 remote httpproxy[5492]: id="0001" severity="info" sys="SecureWeb" sub="http" name="http access" action="pass" method="CONNECT" srcip="172.20.47.77" dstip="106.10.198.33" user="" group="" ad_domain="" statuscode="200" cached="0" profile="REF_DefaultHTTPProfile (Default Web Filter Profile)" filteraction="REF_DefaultHTTPCFFAction (Default content filter action)" size="4248" request="0xae92c00" url="https://ads.yahoo.com/" referer="" error="" authtime="0" dnstime="8" cattime="228" avscantime="0" fullreqtime="80037102" device="1" auth="0" ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" exceptions="" category="154" reputation="trusted" categoryname="Web Ads" application="yahoo" app-id="553"
2016:10:07-09:22:09 remote httpproxy[5492]: id="0001" severity="info" sys="SecureWeb" sub="http" name="http access" action="pass" method="CONNECT" srcip="172.20.47.77" dstip="172.217.25.161" user="" group="" ad_domain="" statuscode="200" cached="0" profile="REF_DefaultHTTPProfile (Default Web Filter Profile)" filteraction="REF_DefaultHTTPCFFAction (Default content filter action)" size="4631" request="0x16e8ea00" url="https://tpc.googlesyndication.com/" referer="" error="" authtime="0" dnstime="583136" cattime="241475" avscantime="0" fullreqtime="86706443" device="1" auth="0" ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" exceptions="" category="145" reputation="neutral" categoryname="Search Engines" application="googads" app-id="815"
2016:10:07-09:22:09 remote httpproxy[5492]: id="0001" severity="info" sys="SecureWeb" sub="http" name="http access" action="pass" method="CONNECT" srcip="172.20.47.77" dstip="172.217.25.161" user="" group="" ad_domain="" statuscode="200" cached="0" profile="REF_DefaultHTTPProfile (Default Web Filter Profile)" filteraction="REF_DefaultHTTPCFFAction (Default content filter action)" size="4631" request="0x18e4d600" url="https://tpc.googlesyndication.com/" referer="" error="" authtime="0" dnstime="583291" cattime="244652" avscantime="0" fullreqtime="86710584" device="1" auth="0" ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" exceptions="" category="145" reputation="neutral" categoryname="Search Engines" application="googads" app-id="815"
2016:10:07-09:22:09 remote httpproxy[5492]: id="0001" severity="info" sys="SecureWeb" sub="http" name="http access" action="pass" method="CONNECT" srcip="172.20.47.77" dstip="172.217.25.161" user="" group="" ad_domain="" statuscode="200" cached="0" profile="REF_DefaultHTTPProfile (Default Web Filter Profile)" filteraction="REF_DefaultHTTPCFFAction (Default content filter action)" size="4631" request="0xa209600" url="https://tpc.googlesyndication.com/" referer="" error="" authtime="0" dnstime="583533" cattime="243934" avscantime="0" fullreqtime="86711519" device="1" auth="0" ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" exceptions="" category="145" reputation="neutral" categoryname="Search Engines" application="googads" app-id="815"
2016:10:07-09:22:09 remote httpproxy[5492]: id="0001" severity="info" sys="SecureWeb" sub="http" name="http access" action="pass" method="GET" srcip="172.20.47.77" dstip="50.97.236.98" user="" group="" ad_domain="" statuscode="200" cached="0" profile="REF_DefaultHTTPProfile (Default Web Filter Profile)" filteraction="REF_DefaultHTTPCFFAction (Default content filter action)" size="957" request="0x16fa4c00" url="http://tags.bluekai.com/site/20267?ret=html&limit=4&btp=1&phint=eid%3D1650&phint=tcat%3D220&phint=crm%3D4&phint=cg%3D97fac6cc1530a629a7c13ed1f7ab0909&phint=btf%3D&phint=btp%3D:a:b:c:d:e&phint=gid%3D1&phint=inid%3D-99&phint=css%3D34&phint=c%3D0&phint=m%3DN&phint=aid%3Dtf&phint=ps%3D1&phint=fm_segment%3D15:12,15:12&phint=pageid%3D2047675&phint=referrer%3Dwww.ebay.com.au&phint=user_type%3D22&phint=symphony%3D0" referer="http://www.ebay.com.au/itm/1-6-SCALE-dragon-WW2-GERMAN-SS-OFFICERS-WHITE-PIPS-AND-DECORATIONS/112156322448?_trksid=p2060778.c100276.m3476&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20140813105702%26meid%3D29ba022992ea4bd783400dd10e50825f%26pid%3D100276%26rk%3D3%26rkt%3D4%26sd%3D112152394027" error="" authtime="0" dnstime="828" cattime="26036" avscantime="0" fullreqtime="647201" device="1" auth="0" ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" exceptions="" category="105" reputation="neutral" categoryname="Business" content-type="text/html" application="ebay" app-id="134"

Related

Web Scraper for Data-Url in Div Python (BeautifulSoup)

I don't know why the program doesn't extract the links from inside the div
I don't know if the error was in defining the div class or the code at the stage of extracting the data-url from the div
here is the current code :
import requests
from bs4 import BeautifulSoup
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
}
url = requests.get("https://www.chosic.com/free-music/all/" , headers=header)
soup = BeautifulSoup(url.content, 'lxml')
list = []
music = soup.find_all('div',{'class':'track-audio'})
for i in music:
i.findAll(['data-url'])
print(i)
output :
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="27306" data-url="https://www.chosic.com/wp-content/uploads/2021/02/happy-clappy-ukulele.mp3" id="waveform27306"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="25944" data-url="https://www.chosic.com/wp-content/uploads/2020/07/Art-Of-Silence_V2.mp3" id="waveform25944"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="26757" data-url="https://www.chosic.com/wp-content/uploads/2020/11/batchbug-sweet-dreams.mp3" id="waveform26757"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="27880" data-url="https://www.chosic.com/wp-content/uploads/2021/04/Luke-Bergs-Bliss.mp3" id="waveform27880"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="27281" data-url="https://www.chosic.com/wp-content/uploads/2021/02/Warm-Memories-Emotional-Inspiring-Piano.mp3" id="waveform27281"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="26021" data-url="https://www.chosic.com/wp-content/uploads/2020/08/fm-freemusic-give-me-a-smile.mp3" id="waveform26021"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="27247" data-url="https://www.chosic.com/wp-content/uploads/2021/02/Monkeys-Spinning-Monkeys.mp3" id="waveform27247"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="27248" data-url="https://www.chosic.com/wp-content/uploads/2021/02/Fluffing-a-Duck.mp3" id="waveform27248"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="27120" data-url="https://www.chosic.com/wp-content/uploads/2021/01/fm-freemusic-inspiring-optimistic-upbeat-energetic-guitar-rhythm.mp3" id="waveform27120"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="25860" data-url="https://www.chosic.com/wp-content/uploads/2020/07/alexander-nakarada-superepic.mp3" id="waveform25860"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="28703" data-url="https://www.chosic.com/wp-content/uploads/2021/08/An-Epic-Story.mp3" id="waveform28703"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="28923" data-url="https://www.chosic.com/wp-content/uploads/2021/08/scott-buckley-jul.mp3" id="waveform28923"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="24515" data-url="https://www.chosic.com/wp-content/uploads/2020/06/John_Bartmann_-_02_-_Happy_African_Village.mp3" id="waveform24515"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="27012" data-url="https://www.chosic.com/wp-content/uploads/2021/01/春
のテーマ-Spring-field-.mp3" id="waveform27012"></div></div>
<div class="track-audio"><div class="waveform before" data-saved="yes" data-track="25897" data-url="https://www.chosic.com/wp-content/uploads/2020/07/Brandenburg-Concerto-no.-3-BWV-1048-Complete-Performance.mp3" id="waveform25897"></div></div>
but i want extract their data-url from div
example :
https://www.chosic.com/wp-content/uploads/2021/04/Luke-Bergs-Bliss.mp3
https://www.chosic.com/wp-content/uploads/2021/02/Warm-Memories-Emotional-Inspiring-Piano.mp3
https://www.chosic.com/wp-content/uploads/2020/08/fm-freemusic-give-me-a-smile.mp3
https://www.chosic.com/wp-content/uploads/2021/02/Monkeys-Spinning-Monkeys.mp3
https://www.chosic.com/wp-content/uploads/2021/02/Fluffing-a-Duck.mp3
https://www.chosic.com/wp-content/uploads/2021/01/fm-freemusic-inspiring-optimistic-upbeat-energetic-guitar-rhythm.mp3
https://www.chosic.com/wp-content/uploads/2020/07/alexander-nakarada-superepic.mp3
https://www.chosic.com/wp-content/uploads/2021/08/An-Epic-Story.mp3
https://www.chosic.com/wp-content/uploads/2021/08/scott-buckley-jul.mp3
https://www.chosic.com/wp-content/uploads/2020/06/John_Bartmann_-_02_-_Happy_African_Village.mp3
https://www.chosic.com/wp-content/uploads/2021/01/春
のテーマ-Spring-field-.mp3
https://www.chosic.com/wp-content/uploads/2020/07/Brandenburg-Concerto-no.-3-BWV-1048-Complete-Performance.mp3
any solution possible ??
.findAll doesn't accept CSS-selectors. Also, you aren't assigning the output from .findAll to anything. Try:
import requests
from bs4 import BeautifulSoup
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
}
url = requests.get("https://www.chosic.com/free-music/all/", headers=header)
soup = BeautifulSoup(url.content, "lxml")
music = soup.find_all("div", {"class": "track-audio"})
for i in music:
m = i.select_one("[data-url]")
print(m["data-url"])
Prints:
https://www.chosic.com/wp-content/uploads/2021/02/happy-clappy-ukulele.mp3
https://www.chosic.com/wp-content/uploads/2020/07/Art-Of-Silence_V2.mp3
https://www.chosic.com/wp-content/uploads/2020/11/batchbug-sweet-dreams.mp3
https://www.chosic.com/wp-content/uploads/2021/04/Luke-Bergs-Bliss.mp3
https://www.chosic.com/wp-content/uploads/2021/02/Warm-Memories-Emotional-Inspiring-Piano.mp3
https://www.chosic.com/wp-content/uploads/2020/08/fm-freemusic-give-me-a-smile.mp3
https://www.chosic.com/wp-content/uploads/2021/02/Monkeys-Spinning-Monkeys.mp3
https://www.chosic.com/wp-content/uploads/2021/02/Fluffing-a-Duck.mp3
https://www.chosic.com/wp-content/uploads/2021/01/fm-freemusic-inspiring-optimistic-upbeat-energetic-guitar-rhythm.mp3
https://www.chosic.com/wp-content/uploads/2020/07/alexander-nakarada-superepic.mp3
https://www.chosic.com/wp-content/uploads/2021/08/An-Epic-Story.mp3
https://www.chosic.com/wp-content/uploads/2021/08/scott-buckley-jul.mp3
https://www.chosic.com/wp-content/uploads/2020/06/John_Bartmann_-_02_-_Happy_African_Village.mp3
https://www.chosic.com/wp-content/uploads/2021/01/春のテーマ-Spring-field-.mp3
https://www.chosic.com/wp-content/uploads/2020/07/Brandenburg-Concerto-no.-3-BWV-1048-Complete-Performance.mp3

python requests to login or fill a form

How to fill a form and get the redirect url from the login.
Hi I am trying to submit a login page.
Tried multiple pages but didn't worked out.
<div class="form-group">
<input name="ctl00$MainContent$ctlLogin$_UserName" type="text" size="18" id="ctl00_MainContent_ctlLogin__UserName" accesskey="u" tabindex="60" placeholder="username" class="form-control" name="username" title="username" />
</div>
<div class="form-group">
<input name="ctl00$MainContent$ctlLogin$_Password" type="password" size="18" id="ctl00_MainContent_ctlLogin__Password" accesskey="p" tabindex="61" onkeyup="onkey(event, this.value, this)" placeholder="password" class="form-control" name="password" title="password" />
</div>
<input type="submit" name="ctl00$MainContent$ctlLogin$BtnSubmit" value="Login" id="ctl00_MainContent_ctlLogin_BtnSubmit" class="btn btn-danger" style="text-transform: uppercase;" />
<input name="ctl00$MainContent$ctlLogin$_IdBook" type="hidden" id="ctl00_MainContent_ctlLogin__IdBook" />
<input name="ctl00$MainContent$ctlLogin$Redir" type="hidden" id="ctl00_MainContent_ctlLogin_Redir" value="wager/welcome.aspx" />
import requests
import json
url = 'http://playsports365.com'
data = requests.get(url)
print(data.text)
form_data = {"username":"username","password":"password","action":"login"}
s = requests.session()
r = s.post(url,form_data)
but somehow it is still taking me the first or login page itself.
You have to scrape values of __VIEWSTATE, __VIEWSTATEGENERATOR, __EVENTVALIDATION, ctl00$MainContent$ctlLogin$BtnSubmit, ctl00$MainContent$ctlLogin$Redir from the home page and add it to your form_data.
import requests
import bs4 as bs
# Create session.
session = requests.Session()
headers = {
'Host': 'playsports365.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'http://playsports365.com',
'Referer': 'http://playsports365.com/default.aspx',
}
# Add headers in session.
session.headers.update(headers)
# Login page request.
login_page_url = 'http://playsports365.com/default.aspx'
response = session.get(login_page_url)
soup = bs.BeautifulSoup(response.text, 'lxml')
# Extract payload data from login page.
event_target = soup.find('input', {'id': '__EVENTTARGET'}).get('value')
event_argument = soup.find('input', {'id': '__EVENTARGUMENT'}).get('value')
view_state = soup.find('input', {'id': '__VIEWSTATE'}).get('value')
view_state_generator = soup.find('input', {'id': '__VIEWSTATEGENERATOR'}).get('value')
event_validation = soup.find('input', {'id': '__EVENTVALIDATION'}).get('value')
btn_submit = soup.find('input', {'name': 'ctl00$MainContent$ctlLogin$BtnSubmit'}).get('value')
re_dir = soup.find('input', {'name': 'ctl00$MainContent$ctlLogin$Redir'}).get('value')
# Add data in payload.
form_data = {
'ctl00$MainContent$ctlLogin$_UserName': 'YOUR USERNAME',
'ctl00$MainContent$ctlLogin$_Password': 'YOUR PASSWORD',
'__EVENTTARGET': event_target,
'__EVENTARGUMENT': event_argument,
'__VIEWSTATE': view_state,
'__VIEWSTATEGENERATOR': view_state_generator,
'__EVENTVALIDATION': event_validation,
'ctl00$MainContent$ctlLogin$BtnSubmit': btn_submit,
'ctl00$MainContent$ctlLogin$Redir': re_dir,
}
# Request for login.
login_url = 'http://playsports365.com/default.aspx'
login_response = session.post(login_url, data=form_data)
print(login_response.status_code, response.text)

how to get values from HTTP Response to Excel with VBA Code

I need your little help to get stock value(corresponding to stock name) from the HTTP Response I got. Received Response is in form of HTML, of which i put some part as code is too long. downwards I have mention the VBA Code i am using but it is showing error. Please anyone help me..!!
Note: Stock Name and Values are present in "Input type"(line 5 from down)
<!-- <table align="left">
<tr>
<td> -->
<div class="table-responsive" style="width: 110%;">
<table border="0" align="left" width="688" cellpadding="5" cellspacing="1" class="table_style table_111111" id="data_table">
<thead>
<tr class="table_header">
<td width="15" class="center_align"><strong></strong></td>
<td width="50" class="left_align"><strong>Security </strong></td>
<td width="20" class="center_align"><strong>ME</strong></td>
<td width="15" class="center_align"><strong>Exch Code</strong></td>
<td width="15" class="center_align"><strong>Tradesmart Trends</strong></td>
<td width="20" class="center_align"><strong>IT</strong></td>
<td width="50" class="center_align"><strong>Expiry Date</strong></td>
<td width="50" class="center_align"><strong>Strike Price</strong></td>
<td width="10" class="center_align"><strong>Opt Type</strong></td>
<td width="32" class="center_align"><strong>Open Price</strong></td>
<td width="40" class="center_align"><strong>Buy Price</strong></td>
<td width="32" class="center_align"><strong>Buy Vol</strong></td>
<td width="41" class="center_align"><strong>Sell Price</strong></td>
<td width="32" class="center_align"><strong>Sell Vol</strong></td>
<td width="41" class="center_align"><strong>Last Price</strong></td>
<td width="28" class="center_align"><strong>High Price</strong></td>
<td width="41" class="center_align"><strong>Low Price</strong></td>
<td width="25" class="center_align"><strong>O.I.</strong></td>
<td width="20" class="center_align"><strong>CAs</strong></td>
<td width="50" class="center_align"><strong> % Change</strong></td>
<td width="50" class="center_align"><strong>Net Change</strong></td>
</tr>
</thead>
<input type='hidden' id='first_watch' name='first_watch' value='current'/><tr class='tinside'><td class="left_align"><input type=checkbox name="stkcode" value="1157(NN)EQ" onClick="checkCheck(4);"></td><td class="left_align">APOLLOTYRE</td><td class="center_align">NSE</td><td class="center_align">163</td><td class="center_align"><A style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #31B404; font-weight: bold;' HREF="/itrade/user/recognia.exe?action=access" >Bullish</A></td><td class="center_align">EQ</td><td class="center_align">-</td><td class="center_align">0.00</td><td class="center_align">- </td><td class="center_align">201.00</td><td class="center_align">0.00</td><td class="center_align"></td><td class="center_align">199.50</td><td class="center_align">1,990</td><td class="center_align">199.50</td><td class="center_align">203.85</td><td class="center_align">198.50</td><td class="center_align"> 0</td><td class="center_align">XD</td> <td class="center_align"> 0.00</td> <td class="center_align"> 0.00</td> </tr><tr class='tinside'><td class="left_align"><input type=checkbox name="stkcode" value="2441(NN)EQ" onClick="checkCheck(5);"></td><td class="left_align">SUNPHARMA</td><td class="center_align">NSE</td><td class="center_align">3351</td><td class="center_align"><A style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #31B404; font-weight: bold;' HREF="/itrade/user/recognia.exe?action=access" >Bullish</A></td><td class="center_align">EQ</td><td class="center_align">-</td><td class="center_align">0.00</td><td class="center_align">- </td><td class="center_align">454.90</td><td class="center_align">0.00</td><td class="center_align"></td><td class="center_align">431.25</td><td class="center_align">66,412</td><td class="center_align">431.25</td><td class="center_align">455.00</td><td class="center_align">426.45</td><td class="center_align"> 0</td><td class="center_align">XD</td> <td class="center_align"> 0.00</td> <td class="center_align"> 0.00</td> </tr></table>
</div>
<!--</td>
</tr>
<tr>
Here is the VBA Code. what I am Using to send POST Req to get stock value in response.
Dim cook As String, bodyk As String, xmlhttp As Object, response As String
Dim getcookres As String, html As New HTMLDocument
Dim document As Object
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
cook = Worksheets("Action").Range("X2").Value
bodyk = Worksheets("Action").Range("X1").Value
URL = "https://www.xxxxxxxx.com/itrade/user/watch.exe?action=C"
xmlhttp.Open "POST", URL, False
xmlhttp.setRequestHeader "Host", "www.xxxxxxxx.com"
xmlhttp.setRequestHeader "Connection", "keep-alive"
xmlhttp.setRequestHeader "Content-Length", "700"
xmlhttp.setRequestHeader "Cache-Control", "max-age=0"
xmlhttp.setRequestHeader "Origin", "https://www.xxxxxxxx.com"
xmlhttp.setRequestHeader "Upgrade-Insecure-Requests", "1"
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
xmlhttp.setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
xmlhttp.setRequestHeader "Referer", "https://www.xxxxxxxx.com/itrade/user/watch.exe?action=C"
xmlhttp.setRequestHeader "Accept-Encoding", "gzip, deflate, br"
xmlhttp.setRequestHeader "Accept-Language", "en-US,en;q=0.9"
xmlhttp.setRequestHeader "Cookie", cook
xmlhttp.send bodyk
html.body.innerHTML = xmlhttp.responseText
'Set document = html.getElementsByid("header").getElementsByid("container")(0).getElementsByClassName("table-responsive")(0).getElementsByid("first_watch")(1)
Set document = html.getElementsByClassName("tinside")
'Debug.Print html.body.innerHTML
Debug.Print document
Sheets(1).Cells(2, 1).Value = document.getElementsByTagName("td")(0).innerText
You can use css selectors to target the td elements
Dim nodeList As Object, i As Long
Set nodeList = html.querySelectorAll("#data_table tr.tinside td")
For i = 0 To nodeList.Length -1
Debug.Print nodeList.item(i).innerText
Next
The whole table you can use id selector
Dim ele As Object
Set ele = html.getElementById("data_table")
' then loop the tr tags and then the td tags

Logging in to this website using requests module in python3

Here's what I have done so far. I had to extract the CSFRToken manually (I don't know regex, so that part is messy). Is CSFR part of cookies? Because my cookies only shows two other ID type params, so I dropped the cookie part and did it this way.
import requests
URL = r'http://login.cheezburger.com/'
client = requests.session()
login_page = client.get(URL)
index = login_page.text.find("CSRFToken")
token = login_page.text[index:index+90].split('"')[-2] # This works, I guarantee :)
#print(token) I checked it manually
login_data = {'rlm': 'Shopper',
'for': r'http://login.cheezburger.com/',
'username': 'myusername',
'password': 'mypassword',
'CSRFToken': token}
req = client.post(URL, data=login_data)
Now, there is no error per say, but I am not logging in to this site either. The text of this request shows that I am still stuck in the login page!
The parameters send are (as shown in the dev tools of firefox):
rlm: 'Shopper'
for: 'http://login.cheezburger.com/'
username: 'myusername',
password: 'mypassword',
CSRFToken: '8uhhbf67-1233-fff3-123g1-123123fsdfs22'
The websites source is as follows (the part that contains the form data):
<div class="contents-msl">
<h2>Client Login</h2>
<p>Enter username and password</p>
<div class="form-all-msl">
<form action="/login.action" id="loginForm" method="post"
enctype="application/x-www-form-urlencoded"><input type=hidden name=rlm
value="Shopper"><input
type=hidden
name=for
value="http%3a%2f%2flogin%cheezburger%2ecom%2f">
<ul class="form-section-msl">
<label class="form-label-left-msl" for="loginUserName">
Username<span class="form-required">*</span>
</label>
<div class="form-input-msl">
<input type="text" class="form-textbox-msl" id="loginUserName" name="username"
size="20">
</div>
<label class="form-label-left-msl" for="loginPwd">
Password<span class="form-required-msl">*</span>
</label>
<div class="form-input-msl">
<input type="password" class="form-textbox-msl" id="loginPwd" name="password"
size="20">
</div>
<div class="form-input-msl">
<div class="form-single-column-msl">
</div>
</div>
</ul>
</div>
<button class="members-btn-msl" type="submit">Login</button>
<input type="hidden" name="CSRFToken" class="CSRFToken" value="8uhhbf67-1233-fff3-123g1-123123fsdfs22" /> </form>
</div>
</div>
You maybe want to add some headers
headers = {
'Accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding':
'gzip, deflate, sdch',
'Accept-Language':
'en-US,en;q=0.8,vi;q=0.6',
'Cache-Control':
'max-age=0',
'Connection':
'keep-alive',
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36',
}
Then add headers to your code:
req = client.post(URL, data=login_data)
Good luck !

SharePoint: Custom Ribbon + IE = Error in cui.debug.js (Invalid argument.)

I am having really hard time debugging this one. I have a standard WebPart in SharePoint 2010 with custom Ribbon on it. Everything works great in FireFox, Safari and Chrome. But when it comes to IE, I get the following error.
Webpage error details
User Agent: Mozilla/4.0 (compatible;
MSIE 8.0; Windows NT 6.1; WOW64;
Trident/4.0; SLCC2; .NET CLR
2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3; .NET4.0C;
.NET4.0E) Timestamp: Thu, 23 Jun 2011
05:29:39 UTC
Message: Invalid argument. Line: 11611
Char: 17 Code: 0 URI:
http://example.com/_layouts/cui.debug.js?rev=seEKIhJXfBClfYcr46fd3w%3D%3D
I am attaching the code snippets I feel that might be helpful to you.
Definition for Contextual Tab:
<ContextualGroup Id="Ribbon.MyWPContextualTabGroup"
Color="Blue"
Title="{title}"
Command="MyWPContextualTab.EnableContextualGroup"
Sequence="502"
ContextualGroupId="MyWPContextualTabGroup">
<Tab Id="Ribbon.MyWPTab"
Title="My Work"
Description="My Work tab description"
Command="MyWPContextualTab.EnableMyWPTab"
Sequence="501">
<Scaling Id="Ribbon.MyWPTab.Scaling">
<MaxSize Id="Ribbon.MyWPTab.MaxSizeNew"
GroupId="Ribbon.MyWPTab.MyWPGroupNew"
Size="MyWPLayout" />
<MaxSize Id="Ribbon.MyWPTab.MaxSizeManage"
GroupId="Ribbon.MyWPTab.MyWPGroupManage"
Size="MyWPLayout" />
<MaxSize Id="Ribbon.MyWPTab.MaxSizeViews"
GroupId="Ribbon.MyWPTab.MyWPGroupViews"
Size="MyWPLayout" />
<MaxSize Id="Ribbon.MyWPTab.MaxSizeShareTrack"
GroupId="Ribbon.MyWPTab.MyWPGroupShareTrack"
Size="MyWPLayout" />
<MaxSize Id="Ribbon.MyWPTab.MaxSizeWorkflows"
GroupId="Ribbon.MyWPTab.MyWPGroupWorkflows"
Size="MyWPLayout" />
<Scale Id="Ribbon.MyWPTab.Scaling.MyWPTabScalingNew"
GroupId="Ribbon.MyWPTab.MyWPGroupNew"
Size="MyWPLayout" />
<Scale Id="Ribbon.MyWPTab.Scaling.MyWPTabScalingManage"
GroupId="Ribbon.MyWPTab.MyWPGroupManage"
Size="MyWPLayout" />
<Scale Id="Ribbon.MyWPTab.Scaling.MyWPTabScalingViews"
GroupId="Ribbon.MyWPTab.MyWPGroupViews"
Size="MyWPLayout" />
<Scale Id="Ribbon.MyWPTab.Scaling.MyWPTabScalingShareTrack"
GroupId="Ribbon.MyWPTab.MyWPGroupShareTrack"
Size="MyWPLayout" />
<Scale Id="Ribbon.MyWPTab.Scaling.MyWPTabScalingWorkflows"
GroupId="Ribbon.MyWPTab.MyWPGroupWorkflows"
Size="MyWPLayout" />
</Scaling>
<Groups Id="Ribbon.MyWPTab.Groups">
<Group Id="Ribbon.MyWPTab.MyWPGroupNew"
Description="New group description"
Title="New"
Command="MyWPContextualTab.EnableMyWPGroupNew"
Sequence="52"
Template="Ribbon.Templates.MyWPTemplate">
<Controls Id="Ribbon.MyWP.New.Controls">
<Button Id="Ribbon.MyWP.New.NewItem"
Command="MyWP.Cmd.NewItem"
Description="Add a new item"
LabelText="New Item"
TemplateAlias="ONERW"
Image32by32="_layouts/images/MyWP/ribbon/newitem-32.png"
Image16by16="_layouts/images/MyWP/ribbon/newitem-16.png" />
</Controls>
</Group>
<Group Id="Ribbon.MyWPTab.MyWPGroupManage"
Description="Manage group description"
Title="Manage"
Command="MyWPContextualTab.EnableMyWPGroupManage"
Sequence="53"
Template="Ribbon.Templates.MyWPTemplate">
<Controls Id="Ribbon.MyWP.Manage.Controls">
<Button Id="Ribbon.MyWP.Manage.ViewItem"
Command="MyWP.Cmd.ViewItem"
Description="View this item"
LabelText="View Item"
TemplateAlias="ONERW"
Sequence="5"
Image32by32="_layouts/images/MyWP/ribbon/viewitem-32.png"
Image16by16="_layouts/images/MyWP/ribbon/viewitem-16.png" />
<Button Id="Ribbon.MyWP.Manage.EditItem"
Command="MyWP.Cmd.EditItem"
Description="Edit this item"
LabelText="Edit Item"
TemplateAlias="ONERW"
Sequence="10"
Image32by32="_layouts/images/MyWP/ribbon/edititem-32.png"
Image16by16="_layouts/images/MyWP/ribbon/edititem-16.png" />
<Button Id="Ribbon.MyWP.Manage.VersionHistory"
Command="MyWP.Cmd.VersionHistory"
Description="Version History"
LabelText="Version History"
TemplateAlias="THRRW"
Sequence="15"
Image32by32="_layouts/images/MyWP/ribbon/versionhistory-32.png"
Image16by16="_layouts/images/MyWP/ribbon/versionhistory-16.png" />
<Button Id="Ribbon.MyWP.Manage.ItemPermissions"
Command="MyWP.Cmd.ItemPermissions"
Description="Item Permissions"
LabelText="Item Permissions"
TemplateAlias="THRRW"
Sequence="20"
Image32by32="_layouts/images/MyWP/ribbon/itempermissions-32.png"
Image16by16="_layouts/images/MyWP/ribbon/itempermissions-16.png" />
<Button Id="Ribbon.MyWP.Manage.DeleteItem"
Command="MyWP.Cmd.DeleteItem"
Description="Delete Item"
LabelText="Delete Item"
TemplateAlias="THRRW"
Sequence="25"
Image32by32="_layouts/images/MyWP/ribbon/deleteitem-32.png"
Image16by16="_layouts/images/MyWP/ribbon/deleteitem-16.png" />
<Button Id="Ribbon.MyWP.Manage.Comments"
Command="MyWP.Cmd.Comments"
Description="Comments"
LabelText="Comments"
TemplateAlias="ONERW"
Sequence="30"
Image32by32="_layouts/images/MyWP/ribbon/comments-32.ico"
Image16by16="_layouts/images/MyWP/ribbon/comments-16.png" />
</Controls>
</Group>
<Group Id="Ribbon.MyWPTab.MyWPGroupViews"
Description="Views group description"
Title="Views"
Command="MyWPContextualTab.EnableMyWPGroupViews"
Sequence="54"
Template="Ribbon.Templates.MyWPTemplate">
<Controls Id="Ribbon.MyWP.Views.Controls">
<Button Id="Ribbon.MyWP.Views.SaveView"
Command="MyWP.Cmd.SaveView"
Description="Save View"
LabelText="Save View"
TemplateAlias="THRRW"
Image32by32="_layouts/images/MyWP/ribbon/saveview-32.png"
Image16by16="_layouts/images/MyWP/ribbon/saveview-16.png" />
<Button Id="Ribbon.MyWP.Views.RenameView"
Command="MyWP.Cmd.RenameView"
Description="Rename View"
LabelText="Rename View"
TemplateAlias="THRRW"
Image32by32="_layouts/images/MyWP/ribbon/renameview-32.png"
Image16by16="_layouts/images/MyWP/ribbon/renameview-16.png" />
<Button Id="Ribbon.MyWP.Views.DeleteView"
Command="MyWP.Cmd.DeleteView"
Description="Delete View"
LabelText="Delete View"
TemplateAlias="THRRW"
Image32by32="_layouts/images/MyWP/ribbon/deleteview-32.png"
Image16by16="_layouts/images/MyWP/ribbon/deleteview-16.png" />
<Label Id="Ribbon.MyWP.Views.CurrentViewLabel"
LabelText="Current View:"
ForId="Ribbon.MyWP.Views.CurrentViewDropDown"
TemplateAlias="THRRW" />
<DropDown Id="Ribbon.MyWP.Views.CurrentViewDropDown"
Command="MyWP.Cmd.CurrentViewDropDown"
PopulateDynamically="true"
PopulateQueryCommand="MyWP.Cmd.CurrentViewDropDown.Populate"
TemplateAlias="THRRW" />
<Button Id="Ribbon.MyWP.Views.SelectColoumns"
Command="MyWP.Cmd.SelectColoumns"
Description="Select Coloumns"
LabelText="Select Coloumns"
TemplateAlias="THRRW"
Image32by32="_layouts/images/MyWP/ribbon/selectcoloumns-32.png"
Image16by16="_layouts/images/MyWP/ribbon/selectcoloumns-16.png" />
<Button Id="Ribbon.MyWP.Views.ShowHideFilters"
Command="MyWP.Cmd.ShowHideFilters"
Description="Show/Hide Filters"
LabelText="Show/Hide Filters"
TemplateAlias="THRRW"
Image32by32="_layouts/images/MyWP/ribbon/showhidefilters-32.png"
Image16by16="_layouts/images/MyWP/ribbon/showhidefilters-16.png" />
<Button Id="Ribbon.MyWP.Views.ViewCompletedItems"
Command="MyWP.Cmd.ViewCompletedItems"
Description="View Completed Items"
LabelText="View Completed Items"
TemplateAlias="THRRW"
Image32by32="_layouts/images/MyWP/ribbon/viewcompleteditems-32.png"
Image16by16="_layouts/images/MyWP/ribbon/viewcompleteditems-16.png" />
<Button Id="Ribbon.MyWP.Views.ClearCompletedItems"
Command="MyWP.Cmd.ClearCompletedItems"
Description="Clear Completed Items"
LabelText="Clear Completed Items"
TemplateAlias="THRRW"
Image32by32="_layouts/images/MyWP/ribbon/clearcompleteditems-32.png"
Image16by16="_layouts/images/MyWP/ribbon/clearcompleteditems-16.png" />
</Controls>
</Group>
<Group Id="Ribbon.MyWPTab.MyWPGroupShareTrack"
Description="Group description"
Title="Share & Track"
Command="MyWPContextualTab.EnableMyWPGroupShareTrack"
Sequence="55"
Template="Ribbon.Templates.MyWPTemplate">
<Controls Id="Ribbon.MyWP.ShareTrack.Controls">
<Button Id="Ribbon.MyWP.ShareTrack.AlertMe"
Command="MyWP.Cmd.AlertMe"
Description="Alert Me"
LabelText="Alert Me"
TemplateAlias="ONERW"
Image32by32="_layouts/images/MyWP/ribbon/alertme-32.png"
Image16by16="_layouts/images/MyWP/ribbon/alertme-16.png" />
</Controls>
</Group>
<Group Id="Ribbon.MyWPTab.MyWPGroupWorkflows"
Description="Group description"
Title="Workflows"
Command="MyWPContextualTab.EnableMyWPGroupWorkflows"
Sequence="56"
Template="Ribbon.Templates.MyWPTemplate">
<Controls Id="Ribbon.MyWP.Workflows.Controls">
<Button Id="Ribbon.MyWP.Workflows.Workflows"
Command="MyWP.Cmd.Workflows"
Description="Workflows"
LabelText="Workflows"
TemplateAlias="ONERW"
Image32by32="_layouts/images/MyWP/ribbon/workflows-32.png"
Image16by16="_layouts/images/MyWP/ribbon/workflows-16.png" />
<Button Id="Ribbon.MyWP.Workflows.ApproveReject"
Command="MyWP.Cmd.ApproveReject"
Description="Approve Reject"
LabelText="Approve Reject"
TemplateAlias="ONERW"
Image32by32="_layouts/images/MyWP/ribbon/approvereject-32.png"
Image16by16="_layouts/images/MyWP/ribbon/approvereject-16.png" />
</Controls>
</Group>
</Groups>
</Tab>
</ContextualGroup>
Definition for Contextual Tab:
<GroupTemplate Id="Ribbon.Templates.MyWPTemplate">
<Layout Title="MyWPLayout"
LayoutTitle="MyWPLayout">
<OverflowSection Type="OneRow"
DisplayMode="Large"
TemplateAlias="ONERW" />
<OverflowSection Type="ThreeRow"
DisplayMode="Medium"
TemplateAlias="THRRW" />
</Layout>
</GroupTemplate>
MyWPContextualTabWebComponent.js:
Type.registerNamespace('ContextualTabWebPart');
var _webPartPageComponentId;
ContextualTabWebPart.CustomPageComponent = function ContextualTabWebPart_CustomPageComponent(webPartPcId, gridId)
{
this._webPartPageComponentId = webPartPcId;
this.$gridId = gridId;
ContextualTabWebPart.CustomPageComponent.initializeBase(this);
}
ContextualTabWebPart.CustomPageComponent.prototype = {
$gridId: null,
init: function ContextualTabWebPart_CustomPageComponent$init() { },
getFocusedCommands: function ContextualTabWebPart_CustomPageComponent$getFocusedCommands()
{
return [
'MyWPContextualTab.EnableMyWPTab',
'MyWPContextualTab.EnableMyWPGroupNew',
'MyWP.Cmd.NewItem',
'MyWPContextualTab.EnableMyWPGroupManage',
'MyWP.Cmd.ViewItem',
'MyWP.Cmd.EditItem',
'MyWP.Cmd.VersionHistory',
'MyWP.Cmd.ItemPermissions',
'MyWP.Cmd.DeleteItem',
'MyWP.Cmd.Comments',
'MyWPContextualTab.EnableMyWPGroupViews',
'MyWP.Cmd.SaveView',
'MyWP.Cmd.RenameView',
'MyWP.Cmd.DeleteView',
'MyWP.Cmd.CurrentViewDropDown',
'MyWP.Cmd.CurrentViewDropDown.Populate',
'MyWP.Cmd.SelectColoumns',
'MyWP.Cmd.ShowHideFilters',
'MyWP.Cmd.ViewCompletedItems',
'MyWP.Cmd.ClearCompletedItems',
'MyWPContextualTab.EnableMyWPGroupShareTrack',
'MyWP.Cmd.AlertMe',
'MyWPContextualTab.EnableMyWPGroupWorkflows',
'MyWP.Cmd.Workflows',
'MyWP.Cmd.ApproveReject'];
},
getGlobalCommands: function ContextualTabWebPart_CustomPageComponent$getGlobalCommands()
{
return [];
},
isFocusable: function ContextualTabWebPart_CustomPageComponent$isFocusable()
{
return true;
},
canHandleCommand: function ContextualTabWebPart_CustomPageComponent$canHandleCommand(commandId)
{
//Contextual Tab commands
var commands = [
'MyWPContextualTab.EnableMyWPTab',
'MyWPContextualTab.EnableMyWPGroupNew',
'MyWP.Cmd.NewItem',
'MyWPContextualTab.EnableMyWPGroupManage',
'MyWP.Cmd.ViewItem',
'MyWP.Cmd.EditItem',
'MyWP.Cmd.VersionHistory',
'MyWP.Cmd.ItemPermissions',
'MyWP.Cmd.DeleteItem',
'MyWP.Cmd.Comments',
'MyWPContextualTab.EnableMyWPGroupViews',
'MyWP.Cmd.SaveView',
'MyWP.Cmd.RenameView',
'MyWP.Cmd.DeleteView',
'MyWP.Cmd.CurrentViewDropDown',
'MyWP.Cmd.CurrentViewDropDown.Populate',
'MyWP.Cmd.SelectColoumns',
'MyWP.Cmd.ShowHideFilters',
'MyWP.Cmd.ViewCompletedItems',
'MyWP.Cmd.ClearCompletedItems',
'MyWPContextualTab.EnableMyWPGroupShareTrack',
'MyWP.Cmd.AlertMe',
'MyWPContextualTab.EnableMyWPGroupWorkflows',
'MyWP.Cmd.Workflows',
'MyWP.Cmd.ApproveReject'];
for (var i = 0; i < commands.length; i++)
{
if (commandId === commands[i]) return true;
}
},
handleCommand: function ContextualTabWebPart_CustomPageComponent$handleCommand(commandId, properties, sequence)
{
if (commandId === 'MyWP.Cmd.NewItem') doActionOnItem(this.$gridId, 'new');
if (commandId === 'MyWP.Cmd.ViewItem') doActionOnItem(this.$gridId, 'view');
if (commandId === 'MyWP.Cmd.EditItem') doActionOnItem(this.$gridId, 'edit');
if (commandId === 'MyWP.Cmd.VersionHistory') doActionOnItem(this.$gridId, 'version');
if (commandId === 'MyWP.Cmd.ItemPermissions') doActionOnItem(this.$gridId, 'perms');
if (commandId === 'MyWP.Cmd.DeleteItem') doActionOnItem(this.$gridId, 'delete');
if (commandId === 'MyWP.Cmd.Comments') doActionOnItem(this.$gridId, 'comments');
if (commandId === 'MyWP.Cmd.AlertMe') doActionOnItem(this.$gridId, 'subscribe');
if (commandId === 'MyWP.Cmd.Workflows') doActionOnItem(this.$gridId, 'workflows');
if (commandId === 'MyWP.Cmd.ApproveReject') doActionOnItem(this.$gridId, 'approve');
if (commandId === 'MyWP.Cmd.ClearCompletedItems') doActionOnItem(this.$gridId, 'clear-completed');
},
getId: function ContextualTabWebPart_CustomPageComponent$getId()
{
return this._webPartPageComponentId;
}
}
ContextualTabWebPart.CustomPageComponent.registerClass('ContextualTabWebPart.CustomPageComponent', CUI.Page.PageComponent);
SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs("MyWPContextualTabPageComponent.js");
Whenever you are calling the js function, write this line:
SP.SOD.executeOrDelayUntilScriptLoaded([YOUR JS FUNCTION HERE], ""sp.ribbon.js"");
This will wait for the ribbon js to load and then execute your js function. See if this helps!

Resources