Search code examples
phpweb-scrapingsimple-html-dom

How can I create a field to change the URL in simple_html_dom?


I'm using simple_html_dom, to extract the Name, price and if they are, the manufacturer in a website.

Now, I want to create a script to do a field where you have to put the URL you wan't to extract in the website.

When you tap in the bottom "Extract", the script change the URL in my code:

 $html->load_file ('URL'); 
to the URL we have put in that field.

How can I do that?


Hello @Richard i have done a html form and it's Working on the action_page.php:

That's the code:

<!DOCTYPE html>
<html>
<body>

<form action="action_page.php" method="get">
  URL:<br>
  <input type="text" name="URL" value="">
  <br><br>
  <input type="submit" value="Submit">
</form> 

<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>

</body>
</html>

And this one the action_page.php:

<html>
<body>

The URL is: <?php echo $_GET["URL"]; ?>

</body>
</html>

Now, how can i do for remplace the URL in my code to extract the prices, for the one we put in the extractor.php and we have also in the action_page.php ?

Thank you!


Solution

  • For that, i have made:

    $html->load_file ($_GET["URL"]);
    

    And in the action_page:

    <!DOCTYPE html>
    <html>
    <body>
    
    <form action="action_page.php" method="get">
      URL:<br>
      <input type="text" name="URL" value="">
      <br><br>
      <input type="submit" value="Submit">
    </form> 
    
    <p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>
    
    </body>
    </html>
    

    Thank you! And best regards