I create a web scraping application in C# 4.0. I use Web Client in this application.
now i am facing problem in a A tag click event. Please see the code below
<a href="javascript:document.pagination.pageNumber.value=2;submitSearchForm('pagination');">2</a>
Please see this image.
I try to download the html in that page. how to execute this href code from Webclient.
Please help.
You cannot execute javascript from WebClient
. You can simulate such request and achieve the required response from the server but it takes some reverse-engineering.
To understand how to get the desired response from the server first you have to perform this operation through browser and record request that is generated by clicking on that link (for that you can use Fiddler Web Debugger). Than you have to recreate such request from your WebClient
, that is - send all the required data to the server properly formatted, along with cookies and correct request type (GET or POST - synchronous or asynchronous).
Why you cannot use WebClient
for javascript execution is nicely described here
And how you can create a request that resembles the one created by javascript click can be deduced from this.