Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8136329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:43:40+00:00 2026-06-06T10:43:40+00:00

I am using Perl to connect to a Site, parse its HTML and extract

  • 0

I am using Perl to connect to a Site, parse its HTML and extract the innerHTML in between the tags. I am trying the easier concept first before trying advanced concepts.

I use LWP::UserAgent to craft my HTTP GET Request to the site and receive my response.

I Store the response in an array as follows:

@res = ($ua->request($req))->content;

Edit: HTML to be parsed:

<div class="new"> this is Line 1 </div>
<div>
      this is Line 2 </div>

Now, I parse each line in the HTTP Response and extract the text between the tags:

foreach $line(@res)
{
chomp $line;
if($line =~ /<div[^>]*?>(.*)<\/div>/)
{
    $match = $1;
    print OUTPUT $match."\n";
}
}

The problems with the above code snippet are:

  1. It matches only the innerHTML for the first successful match. It does not print all the successful matches. I am not sure why, the loop should be working according to me. The value of the variable, $match should be overwritten with the contents of capture buffer after every successful match.

  2. It will not be able to extract the text between the innerHTML if the tag spans across multiple lines. You have the opening div tag on the first line, innerHTML on the next line and the closing div tag on the following line.

I am unable to write the HTML in this post, so have given the description.

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:43:42+00:00Added an answer on June 6, 2026 at 10:43 am

    Using a robust HTML parser:

    use HTML::TreeBuilder::XPath qw();
    
    my $tree = HTML::TreeBuilder::XPath->new;
    $tree->parse($http_response->content);
    
    for my $node ($tree->findnodes('//div')) {
        print $_->as_HTML for @{ $node->content_array_ref };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to download a file from a site using perl. I chose
I am trying to connect to Oracle using Perl. I am trying to connect
I'm trying to use Net::SSH::Perl to connect using public keys with this code: my
I am using Expect in perl to connect to remote machine and execute certain
How to connect to Active Directory from Perl? I am using the Net::LDAP Module.
I have some tasks on a site in php using nginx that I'm trying
I'm using Perl to connect to 2 different databases (MySQL and Sybase) using DBI,
I am using Perl's DBD::ODBC to connect to an Oracle database. However, an issue
I am trying to run simple perl dbi example script to connect to mysql
I'm using perl DBI to connect to a SQL Server. This server uses windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.