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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:00:09+00:00 2026-05-23T09:00:09+00:00

Below is a link crawler that gets the urls of a page in a

  • 0

Below is a link crawler that gets the urls of a page in a given depth. At the end of it I added a regular expression to match all the emails of the url that is just crawled. As you can see in the second part, it file_get_content the same page it just downloaded, meaning twice the execution time, bandwidth etc.

The question is how can I merge those two parts to use the first downloaded page, to avoid getting it again? Thank you.

function crawler($url, $depth = 2) {

    $dom = new DOMDocument('1.0');
    if (!$parts || !@$dom->loadHTMLFile($url)) {
        return;
    }
.
.
.

//this is where the second part starts

  $text = file_get_contents($url);
  $res = preg_match_all("/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", $text, $matches);

}
  • 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-23T09:00:10+00:00Added an answer on May 23, 2026 at 9:00 am

    Replace:

    $text = file_get_contents($url);
    

    with:

    $text = $dom->saveHTML();
    

    http://www.php.net/manual/en/domdocument.savehtml.php

    Alternatively, in the first part of your function, you could save the HTML into a variable using file_get_contents, then pass it to $dom->loadHTML. That way you can then reuse the variable with your regex.

    http://www.php.net/manual/en/domdocument.loadhtml.php

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

Sidebar

Related Questions

The below link has my web page and i would like to validate all
I have used the below link to end a session. http://pure-essence.net/2010/02/14/jquery-session-timeout-countdown/ In that i
In given below link when we refresh our page it briefly shows the expanded
In firefox, if the user clicks the below link before the page loads, it
i used the project, in the below link http://aptogo.co.uk/2011/09/opencv-framework-for-ios/ when i integrate that project
Referring to the below link: http://www.javaworld.com/javaworld/jw-11-1998/jw-11-techniques.html?page=2 The composition approach to code reuse provides stronger
In the page found in below link(bg-button.html), I have put round image as a
Im new to python and in my code below: I have a crawler that
At below link: Examples of GoF Design Patterns in Java's core libraries that java.lang.Object#toString()
I downloaded the source code from the below link and added to my project.

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.