0

I have a Internet explorer navigate to a page and I am able to get the page in an array. What I want to do is get content of a div file, for example the page returns

<div class="someClass">Text in div</div> 

and I want to get that text, how would I do it? I was thinking of trying

->content("someClass");

but it wouldn't work.

daxim
  • 39,270
  • 4
  • 65
  • 132
Grigor
  • 4,139
  • 10
  • 41
  • 79
  • 2
    Please do not ask several questions in one question, Stack Overflow does not work well that way. I have removed the latter part, you can still get the original text from [revisions](http://stackoverflow.com/posts/11056483/revisions). If you think that part is substantially different from the primary question, take the text and [open a new question](http://stackoverflow.com/questions/ask). – daxim Jun 15 '12 at 18:53
  • Thanks for notifying me. – Grigor Jun 15 '12 at 19:51

1 Answers1

2

With Web::Query:

use Web::Query qw();
use WWW::Mechanize qw();
my $mech = WWW::Mechanize->new;
$mech->get('file:///tmp/so11056483.html');
Web::Query
    ->new_from_html($mech->content)
    ->find('div.someClass')
    ->text

expression returns the string Text in div

daxim
  • 39,270
  • 4
  • 65
  • 132
  • how would I put that in a variable? – Grigor Jun 15 '12 at 19:52
  • Use the [ordinary assignment operator](http://p3rl.org/op#Assignment-Operators), like with any other expression. – daxim Jun 15 '12 at 19:59
  • didn't work, is there a way of doing this using www::mechanize? – Grigor Jun 15 '12 at 20:22
  • what's the qw() after the names? – Grigor Jun 15 '12 at 20:28
  • An empty list, constructed with the [`qw` operator](http://p3rl.org/op#qw%2fSTRING%2f). Read http://stackoverflow.com/q/6547453#comment-7714112 for the reason. – daxim Jun 15 '12 at 20:31
  • when it says can't locate WWW/Mechanize.pm does that mean I have to install the module by doing cpan WWW::Mechanize? – Grigor Jun 15 '12 at 20:33
  • [Yes.](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) – daxim Jun 15 '12 at 20:35
  • it says "Running make install make test had returned bad status, won't install without force." How do I instal lthis? – Grigor Jun 15 '12 at 20:44
  • [Open a new question](http://stackoverflow.com/questions/ask) and provide the full log. – daxim Jun 15 '12 at 20:52