Scrapy parsing of the hidden information appearing after link click - javascript

I try to parse some hidden information:
<a id="showInfoBtn" rel="nofollow" title="SomeTitle" href="some_link/some_hash"
onclick="return showInfo(event)">Info showed here after click</a>
When I manually click to this link, only get request to http://www.google-analytics.com appears at the firebug. And page not reloaded - only info showed as a link text.
How can I get info by scrapy?

I did not understand very well if what you're trying to get is to show some info inside the a tag or in other part of the page. But in any of the cases that will also depend on what does the showInfo() function return.
If the first case is what you need and showInfo() returns the text with the info, i believe this is what you're looking for:
<a id="showInfoBtn" rel="nofollow" title="SomeTitle" href="#" onclick="this.innerHTML=showInfo(event)">
Info showed here after click
</a>
Here's a demo with the example http://jsfiddle.net/P49Dv/ ;)

Related

How can I replace Current page with another page then open current page in another tab

Hello my Wonderful Developers, I need help on this
Let say my website is https://nkiri.pw/ and I want to click on a button or Link, I want my current page to be replace by this page https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3 and my present page should open another page automatically. How can I achieve this successfully ?
I was able to solve it by doing this:
<a role="button" id='mike' href="<?php echo "https://".$_SERVER['SERVER_NAME']."/" ?>" target="_blank" class="btn btn-primary">Primary</a>
<script>let linkElement = document.getElementById("mike"); linkElement.addEventListener("click", openNew);function openNew() {window.open("https://itinerarycarter.com/h9xdx19n?key=2053deb616c8b3ac8566b44a8ec7c092", "_self");}</script>
You are using a hyperlink. So you have a href="" in your html tag. You can also set the target (where the page should be opened) to _blank. This means, that the page will be opened in another tab. So if you write it like this:
href="https://nkiri.pw/" target="_blank"
It will open your current page in another tab. Then you can open the new page with js.
let linkElement = Document.getElementById("yourIdOfTheLinkElement");
linkElement.addEventListener(function() {
window.open("https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3", "_self");
});

How To make it so when you click an html button, it downloads a file to the persons computer?

<button type="submit" class="myButton" onclick="window.open('test.txt')">Money Dispenser</button>
Is the current code i have, and does not do anything at all when i click it. ( I want it to download test.txt to the computer or device of the user who cliked it)
I don't really understand what you are trying to achieve using a submit button, if it's not mandatory I'd use an <a>.
With pure HTML5 using the download attribute
<a href="test.txt" download>Money Dispenser</a>
Or with Javascript if you have to use a <button>
This has already been covered grealy in this question
But the gist of it is, create a function to download files as shown on that thread and add it to your <button>
<button onclick="donwloaURI('data:text/plain,Test', 'Test.txt')">Money Dispenser</button>
You can use the HTML download attribute to specify that the target will be downloaded when a user clicks on the hyperlink.
<a href="/download-file-path-here" download>
Money Dispenser
</a>
You can do using:
<a href="data:text/plain;charset=UTF-8,test.txt" download>Download</a>

Javascript Bookmarklet Duplicating URI / URL

I have the following bookmarklet:
javascript:findlink=document.getElementsByClassName(%22download_link%22)[2].href;window.open('https://myfiledrive.com/users/files/add?url='+findlink,'_blank');void(0);
Example:
<a class="download_link" href="example.com/pdf1.pdf">
<a class="download_link" href="example.com/pdf2.pdf">
<a class="download_link" href="example.com/pdf3.pdf">
Basically, it searches the currently active page, for the third iteration of an tag with the class "download_link", and stores it in the variable "findink",
Then it loads 'https://myfiledrive.com/users/files/add?url='+findlink
In the above example it should load:
https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf
but what ends up happening is that this gets loaded:
https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf?url=example.com/pdf3.pdf
so basically it's duplicating url=
What am I doing wrong? Thanks.
The url param shouldn't be duplicated. You're not appending to findlink or anything. You can try the snippet below, it's exactly as you've posted.
Chrome will block the popup, but if you read the error message, there's no duplication going on:
Blocked opening 'https://myfiledrive.com/users/files/add?url=https://stacksnippets.net/example.com/pdf3.pdf' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.
url is only in there once no matter how many times I click.
<a class="download_link" href="example.com/pdf1.pdf">1</a>
<a class="download_link" href="example.com/pdf2.pdf">2</a>
<a class="download_link" href="example.com/pdf3.pdf">3</a>
download

Clicking a JavaScript link on website

I am trying through VBA to generate automatically a report from my bank's website.
I managed to reach the website and plug in my user id and password without any problem. I've reached the page where I can normally generate the report.
Now I have to simulate a click on the link... But I can't manage to do it.
Here is a screenshot of the website, with the HTML code of the link I have to click on to generate the report (Summary Report Copy).
Here is the HTML code of the link I need to click on:
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false" class="">Summary Report Copy</a>
I've tried this line of VBA code, but doesn't work:
IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestatus").FireEvent "onclick"
How can I click on this "Summary Report Copy" thanks to VBA?
Here is the complete HTML code of the part of the webpage where the link is located. Maybe I am not using the right ID?
<td width="290px">
<span id="irCustomStepOne:headerDataTableId:23:reportNmGrp">
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false">Summary Report Copy</a>
<a id="irCustomStepOne:headerDataTableId:23:reportnamePrint" href="#" style="float:left;display:none;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if (!onReportLink(\'23\')) return false;','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamePrint\':\'irCustomStepOne:headerDataTableId:23:reportnamePrint\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Print\'},\'_blank\')');return false">Summary Report Copy</a>
<span id="irCustomStepOne:headerDataTableId:23:rpId" style="float:left;display:none;">3368127</span>
</span>
</td>
This always worked for me. Try it please:
For each lnk in IE.Document.getElementByTagName("a")
If lnk.ID = "irCustomStepOne:headerDataTableId:23:reportnamestat‌​us" Then
lnk.Click
Exit For
Next
You might have to wait for the page to be fully loaded. Something like
Do: VBA.DoEvents: Loop While IE.Busy ' wait for the page to load
Dim el 'As IHTMLElement
Set el = IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestat‌​us")
If el Is Nothing Then el = IE.Document.querySelector("a[title='Summary Report Copy']")
If el Is Nothing Then MsgBox("Link not found!") : Exit Sub
el.click
Do: VBA.DoEvents: Loop While IE.Busy ' wait for next page to load

Why does target not working here

First I make an index page containing frame and I named all frames as nasa google you tube etc .
then on search page
<input id="main_category_lan1" value="test" />
<a href="javascript:void(0)"
onmouseover="
window.open('http://nasasearch.nasa.gov/search?utf8=%E2%9C%93&affiliate=nasa&query='
+document.getElementById('main_category_lan1').value)", target="nasa">s</a>
<a href="javascript:void(0)"
onmouseover="window.open('https://www.youtube.com/results?search_query=lecture'
+document.getElementById('main_category_lan1').value)",target="google">e</a>
but this is not working ,every time it open in new tab. Also I want to open both the pages bye a single button.
What should I do? Thanks.
Pass _self in target.
Read this link for more info about target
http://www.w3schools.com/tags/att_base_target.asp

Categories