Link to home
Start Free TrialLog in
Avatar of Adrian Zafir
Adrian Zafir

asked on

Scraping ASP.net pages from within the browser

I'm trying to scrape an ASPX page within the browser using JavaScript. From research, I can see that to traverse through the pages I need to submit forms. Is this possible to do without refreshing the initial page the code is running on? In other words, is this something that can be done within the browser?

I'm using the Artoo library, which has an ajaxSpider() function, which is based on jQuery's Ajax function. I can retrieve other pages from the same domain, but I don't know if it is possible to submit a form with this tool.

For more context I have to post variables such as __EVENTTARGET and __VEIWSTATE.
Avatar of Adrian Zafir
Adrian Zafir

ASKER

I have tried submitting the form with an event, but I don't really know what I am doing.
Avatar of Mrunal
Hi
If you need to navigate through all aspx pages, then you can do it in JavaScript or with jQuery (easy syntactically).
Main logic is - Catch form submit event  and prevent default submit behaviour of form and add code which you want to execute.
Reference:
https://code.tutsplus.com/tutorials/submit-a-form-without-page-refresh-using-jquery--net-59

For passing post variables, you can use:
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

Open in new window

Thank you Mrunal.

Is it possible to submit the form without visiting the website itself, say though an Ajax request?

For example, $.ajax({URL: URL, data: __viewState = scrapedViewState etc...
Yes it is possible.
But for this if both domains are different then you have to make enable cors = true for $.ajax call.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.