I'm using the Html Agility Pack for getting and parsing HTML pages. It offers many possibilities, including XPath selectors.
Today I had a problem with posting data to a webpage. It's possible to call the HtmlWeb
Load
function with a second "POST" parameter, but it offers no easy way to add values to be posted.
After a while of searching I came across this solution: add this two functions to the HtmlWeb
class. (You can get the source in download section, too)
Source: http://htmlagilitypack.codeplex.com/Thread/View.aspx?ThreadId=14255
Now posting is easy. Example:
(hw
is an HtmlWeb
object and doc
an HtmlDocument
object)
If you need to use cookies, too, you need to modify the HtmlWeb
a little more, because there is a little bug.
First add a new private
variable:
Then find this section:
And change it into:
Now you just have to activate the usage of cookies in your HtmlWeb
object:
That's it! Enjoy easy form posting with a full cookie jar (:
I'm using the Html Agility Pack for getting and parsing HTML pages. It offers many possibilities, including XPath selectors.
Today I had a problem with posting data to a webpage. It's possible to call the HtmlWeb
Load
function with a second "POST" parameter, but it offers no easy way to add values to be posted.
After a while of searching I came across this solution: add this two functions to the HtmlWeb
class. (You can get the source in download section, too)
Source: http://htmlagilitypack.codeplex.com/Thread/View.aspx?ThreadId=14255
Now posting is easy. Example:
(hw
is an HtmlWeb
object and doc
an HtmlDocument
object)
If you need to use cookies, too, you need to modify the HtmlWeb
a little more, because there is a little bug.
First add a new private
variable:
Then find this section:
And change it into:
Now you just have to activate the usage of cookies in your HtmlWeb
object:
That's it! Enjoy easy form posting with a full cookie jar (:
댓글 없음:
댓글 쓰기