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 1074631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:09:29+00:00 2026-05-16T21:09:29+00:00

HI, im trying to get the host from a url. sub scrape { my

  • 0

HI, im trying to get the host from a url.

sub scrape {
my @m_error_array;
my @m_href_array;
my @href_array;
my ( $self, $DBhost, $DBuser, $DBpass, $DBname ) = @_;
my ($dbh, $query, $result, $array);
my $DNS = "dbi:mysql:$DBname:$DBhost:3306";
$dbh = DBI->connect($DNS, $DBuser, $DBpass ) or die $DBI::errstr;
if( defined( $self->{_process_image} ) && ( -e 'href_w_' . $self->{_process_image} . ".txt" ) ) {
    open  ERROR_W, "error_w_" . $self->{_process_image} . ".txt";
    open  M_HREF_W, "m_href_w_" . $self->{_process_image} . ".txt";
    open  HREF_W, "href_w_" . $self->{_process_image} . ".txt";
    @m_error_array = ( split( '|||', <ERROR_W> ) );
    @m_href_array = ( split( '|||', <M_HREF_W> ) );
    @href_array = ( split( '|||', <HREF_W> ) );
    close ( ERROR_W );
    close ( M_HREF_W );
    close ( HREF_W );
}else{
    @href_array = ( $self->{_url} );
}
my $z = 0;
while( @href_array ){
    if( defined( $self->{_x_more} ) && $z == $self->{_x_more} ) {
        last;
    }
    if( defined( $self->{_process_image} ) ) {
        $self->write( 'm_href_w', @m_href_array );
        $self->write( 'href_w', @href_array );
        $self->write( 'error_w', @m_error_array );
    }
    $self->{_link_count} = scalar @m_href_array;
    my $href = shift( @href_array );
    my $info = URI->new($href);
    my $host = $info->host;
    $host =~ s/^www\.//;
    $result = $dbh->prepare("INSERT INTO `". $host ."` (URL) VALUES ('$href')");
    if( ! $result->execute() ){
        $result = $dbh->prepare("CREATE TABLE `" . $host . "` ( `ID` INT( 255 ) NOT NULL AUTO_INCREMENT , `URL` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `ID` )) ENGINE = MYISAM ;");
        $result->execute()
    }
    $self->{_current_page} = $href;
    my $response = $ua->get($href);
    my $responseCode = $response->code;
    print $responseCode;
}

}

Towards te end the line my $host = $info->host; is throwing Can't locate object method "host" via package "URI::_generic"

Can anyone explain this?

Regards,

Phil

  • 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-05-16T21:09:29+00:00Added an answer on May 16, 2026 at 9:09 pm

    URI->new creates instances of a subclass of URI, depending on the scheme of the url you give it. Those subclasses might be URI::http, URI::file, URI::mailto, or something completely different. If URI doesn’t have a specialized subclass for the kind of url you gave it, it’ll create an instance of URI::_generic.

    Each of those URI subclasses have different methods. URI::http happens to have a host method, but most others don’t. You’re calling ->host on something that isn’t a URI::http or similar, and therefore doesn’t have a host method.

    You probably expected all the strings you pass to URI->new to be http urls. That doesn’t seem to be the case, so you might want to check your data. Otherwise, if you do want to handle non-http urls, you should make sure a method actually exists for that instance before calling it, for example by using ->can or ->isa.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the base URL from the worker role. I can't
I'm trying to get just the id from a vimeo URL. Is there a
I'm trying to get a response from an outside url using the below code,
Based on this answer Get the subdomain from a URL , I am trying
I'm very new to c++ and boost. I'm trying to get the host name
I am trying to get Android USB host mode to work; but I need
I am trying to get the latest event timestamp for each host, google search
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I get this error when trying to get a feed from Google Analytics API.
I'm trying to change some php code so that i get my values from

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.