HTML::T...:ASP_NET(3)
π HTML::TreeBuilderX::ASP_NET π
okay bestie, buckle up, because this one is HTML::TreeBuilderX::ASP_NET β the module that scrapes ASP.NET / VB.NET sites that do all their navigating through Javascript POST-backs. yes, that kind of site. we're going in. π¦
β¨ NAME β¨
HTML::TreeBuilderX::ASP_NET β Scrape ASP.NET/VB.NET sites which utilize Javascript POST-backs. π
β¨ SYNOPSIS β¨
my $ua = LWP::UserAgent->new;
my $resp = $ua->get('http://uniqueUrl.com/Server.aspx');
my $root = HTML::TreeBuilder->new_from_content( $resp->content );
my $a = $root->look_down( _tag => 'a', id => 'nextPage' );
my $aspnet = HTML::TreeBuilderX::ASP_NET->new({
element => $a
, baseURL =>$resp->request->uri ## takes into account posting redirects
});
my $resp = $ua->request( $aspnet->httpResponse );
## or the easy cheating way see the SEE ALSO section for links
my $aspnet = HTML::TreeBuilderX::ASP_NET->new_with_traits( traits => ['htmlElement'] );
$form->look_down(_tag=> 'a')->httpResponse
β¨ DESCRIPTION β¨
so basically: this scrapes ASP.NET sites that lean on the language's __VIEWSTATE, __EVENTTARGET, __EVENTARGUMENT, __LASTFOCUS, et al. and it hands you back a HTTP::Response from the form via the method ->httpResponse. iconic behaviour honestly. π
in this scheme, sooo many links on a webpage look like javascript functions. the default one is __doPostBack(eventTarget, eventArgument). ASP.NET keeps two hidden fields that record state: __VIEWSTATE and __LASTFOCUS. this module abstracts each link with a method that uses an HTTP post-back to the server. the Javascript behind __doPostBack literally just appends __EVENTTARGET=$eventTarget&__EVENTARGUMENT=$eventArgument onto the POST request from the parent form and submits it. when the server gets that request it decodes and decompresses the __VIEWSTATE and uses it, along with the new __EVENTTARGET and __EVENTARGUMENT, to perform the action β which is often no more than serializing the data right back into the __VIEWSTATE. the way that is a whole circle of life. π₯
sometimes devs cloak __doPostBack(target,arg) with names like changepage(arg) which just call __doPostBack("target", arg). this module handles that use case too, using the explicit eventTriggerArugment in the constructor. (yes, that spelling. we don't fix it, we love it as it is. π)
this flow is a bane on RESTLESS http and makes no sense whatsoever. Thanks Microsoft. π
.-------------------------------------------------------------------.
| HTML FORM 1 |
| <form action="Server.aspx" method="post"> |
| <input type="hidden" name="__VIEWSTATE" value="encryptedXML-FOO"> |
| <a>1</a> | |
| <a href="javascript:__doPostBack('gotopage','2')">2</a> |
| ... |
'-------------------------------------------------------------------'
|
v
_________________________________
\ \
) User clicks the link named "2" )
/________________________________/
|
v
.------------------------------------------------------------------------.
| POST http://aspxnonsensery/Server.aspx |
| Content-Length: 2659 |
| Content-Type: application/x-www-form-urlencoded |
| |
| __VIEWSTATE=encryptedXML-FOO&__EVENTTARGET=gotopage1&__EVENTARGUMENT=2 |
'------------------------------------------------------------------------'
|
v
.----------------------------------------------------------------------.
| HTML FORM 2 |
| (different __VIEWSTATE) |
| <form action="Server.aspx" method="post"> |
| <input type="hidden" name="__VIEWSTATE" value="encryptedXML-BAR"> |
| <a href="javascript:__doPostBack('gotopage','1')">1</a> | |
| <a>2</a> |
| ... |
'----------------------------------------------------------------------'
πΈ METHODS πΈ
IN ADDITION TO ALL OF THE METHODS FROM HTTP::Request::Form π
β ->new({ hashref })
takes a HashRef, returns a new instance. some of the possible key/values are:
form => $htmlElementβ optional: you explicitly send theHTML::Elmenetrepresenting the form. if you don't, one gets implicitly deduced from$self->elementβ which makeselement=>$htmlElementa requirement. π«ΆeventTriggerArgument => $hashRefβ not needed if you supply an element. this takes a HashRef and will createHTML::Elementsthat mimic hidden input fields. from which to tack onto the$self->form. πelement => $htmlElementβ not needed if you send aneventTriggerArgument. attempts to deduce the__EVENTARGUMENTand__EVENTTARGETfrom the'href'attribute of the element, just as if the two were supplied explicitly. it will also be used to deduce a form by looking up in the HTML tree if one is not supplied. π¦debug => *0|1β optional: sends the debug flag H:R:F, default is off.baseURL => $uriβ optional: sets the base of the URL for the post action.
β ->httpRequest
returns an HTTP::Request object for the HTTP POST. π¬
β ->hrf
explicitly return the underlying HTTP::Request::Form object. all methods fallback here anyway, but this will return that object directly. π
π FUNCTIONS π
None of these are exported... π (they're just there, for you, if you want them)
β createInputElements( {eventTarget => eventArgument} )
helper function, takes two values in a HashRef. assumes the key is the __EVENTTARGET and the value is the __EVENTARGUMENT, returns two HTML::Element pseudo-input fields with the information. π§
β parseDoPostBack( $str )
accepts a string that is often the "href" attribute of an HTTP::Element. it simply parses out the call to Javascript, using regexes, and makes the two args useable to perl in the form of an HashRef. β
β¨ SEE ALSO β¨
HTML::TreeBuilderX::ASP_NET::Roles::htmlElementβ for an easy way to glue the two together π«ΆHTTP::Requestβ for the object the methodhtmlElementreturns πHTTP::Request::Formβ for a base class, to which all methods are valid πHTML::Elementβ for the base class of all HTML tokens π¦
β¨ AUTHOR β¨
Evan Carroll, <me at evancarroll.com> π
β¨ BUGS β¨
None, though much more support should be added to ->element. not everything is a simple anchor tag. π
β¨ SUPPORT β¨
you can find documentation for this module with the perldoc command. bestie, it's right there:
perldoc HTML::TreeBuilderX::ASP_NET
you can also look for information at:
- RT: CPAN's request tracker β <http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-TreeBuilderX-ASP_NET>
- AnnoCPAN: Annotated CPAN documentation β <http://annocpan.org/dist/HTML-TreeBuilderX-ASP_NET>
- CPAN Ratings β <http://cpanratings.perl.org/d/HTML-TreeBuilderX-ASP_NET>
- Search CPAN β <http://search.cpan.org/dist/HTML-TreeBuilderX-ASP_NET>
β¨ COPYRIGHT & LICENSE β¨
Copyright 2008 Evan Carroll, all rights reserved. πΈ
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
okay and that's the whole page, no cap. go scrape responsibly, the __VIEWSTATE waits for no one. π
β¨
this has been HTML::TreeBuilderX::ASP_NET, perl v5.42.0, 2025-07-25 β mwah, ily, go read the source bestie π«Άππ¦
π¦ where this page comes from
- fedora 43: perl-HTML-TreeBuilderX-ASP_NET 0.09-36.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms