开发者

crawling / scraping a search form based webpages

开发者 https://www.devze.com 2023-03-05 14:07 出处:网络
I want to crawl/scrape a webpage which has a form开发者_如何学C to be precise following is the URL

I want to crawl/scrape a webpage which has a form开发者_如何学C to be precise following is the URL

http://lafayetteassessor.com/propertysearch.cfm

The problem is, i want to make a search and save the result in a webpage.

  1. my search string will always give a unique page, so result count won't be a problem.
  2. the search over there doesn't search on URL (e.g. google searching url contains parameters to search). How can i search from starting page (as above) and get the result page ?

please give me some idea. I am using C#/.NET.


If you look at the forms on that page, you will notice that they use the POST method, rather than the GET method. As I'm sure you know, GET forms pass their parameters as part of the URL, eg mypage?arg1=value&arg2=value

However, for POST requests, you need to pass the parameters as the request body. It takes the same format, it's just passed in differently. To do this, use code similar to this:

HttpRequest myRequest = (HttpRequest)WebRequest.Create(theURL);
myRequest.Method = "post";

using(TextWriter body = new StreamWriter(myRequest.GetRequestStream())) {
    body.Write("arg1=value1&arg2=value2");
}

WebResponse theResponse = myRequest.GetResponse();

//do stuff with the response

Don't forget that you still need to escape the arguments, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消