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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:26:18+00:00 2026-05-27T08:26:18+00:00

Goal: I want to scrape the word Paris inside an iframe using cURL. Say

  • 0

Goal: I want to scrape the word “Paris” inside an iframe using cURL.

Say you have a simple page containing an iframe:

<html>
<head>
<title>Curl into this page</title>
</head>
<body>

<iframe src="france.html" title="test" name="test">

</body>
</html>

The iframe page:

<html>
<head>
<title>France</title>
</head>
<body>

<p>The Capital of France is: Paris</p>

</body>
</html>

My cURL script:

<?php>

// 1. initialize

$ch = curl_init();

// 2. The URL containing the iframe

$url = "http://localhost/test/index.html";

// 3. set the options, including the url

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// 4. execute and fetch the resulting HTML output by putting into $output

$output = curl_exec($ch);

// 5. free up the curl handle

curl_close($ch);

// 6. Scrape for a single string/word ("Paris") 

preg_match("'The Capital of France is:(.*?). </p>'si", $output, $match);
if($match) 

// 7. Display the scraped string 

echo "The Capital of France is: ".$match[1];

?>

Result = nothing!

Can someone help me find out the capital of France?! 😉

I need example of:

  1. parsing/grabbing the iframe url
  2. curling the url (as I’ve done with the index.html page)
  3. parsing for the string “Paris”

Thanks!

  • 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-27T08:26:19+00:00Added an answer on May 27, 2026 at 8:26 am

    –Edit–
    You could load the page contents into a string, parse the string for iframe, then load the iframe source into another string.

    $wrapperPage = file_get_contents('http://localhost/test/index.html');
    
    $pattern = '/\.*src=\".*\.html"\.*/';
    
    $iframeSrc = preg_match($pattern, $wrapperPage, $matches);
    
    if (!isset($matches[0])) {
        throw new Exception('No match found!');
    }
    
    $src = $matches[0];
    
    $src = str_ireplace('"', '', $src);
    $src = str_ireplace('src=', '', $src);
    $src = trim($src);
    
    $iframeContents = file_get_contents($src);
    
    var_dump($iframeContents);
    

    –Original–

    Work on your acceptance rate (accept answers to previously answered questions).

    The url you are setting the curl handler to is the file wrapping the i-frame, try setting it to the url of the iframe:

    $url = "http://localhost/test/france.html";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively simple goal: I want to create a Cocoa application which
I have a simple question that is confusing me. Goal : I want to
goal : I want to place a text after the submit button using hook_form_alter.
goal: I have the string 1234432144 I want to only replace the first 2
I have the pages that I want to set as a goal in Google
I have some questions regarding my MVC learning curve Goal: I want to get
Goal I want to simulate with a request to a HTML-document just the way
Goal: I want to fill a page with 100,000 digits of π, one digit
My Goal: I want to create an HTML division that is styled to be,
Goal : I want flash to have accurate information about the width and height

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.