Change language

Web Recycling in PHP Using Simple HTML DOM Parser

|
You can download it by clicking on this link.Example 1:The example below shows how to use this API to display Google search on localhost.
  • HTML code: < html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport" content = " width = device-width, initial-scale = 1.0 " > < meta http-equiv = "X-UA-Compatible" content = " ie = edge " > < title > Document < / title > < / head > < body > < form action = "GoogleSearch.php" method = " POST " > < input type = "text" name = "search" > < br > < br > < button > Search < / button > < / form > < / body > < / html >
  • PHP Code:  
    // If the file is in the API directory include ( ’simple_html_dom.php’ );  
    // Extract DOM $html = file_get_html ( http://www.google.com/search?q= . $_ POST [ " search " ]);  
    // DOM display echo $html ;  
    ?>
  • Output:output on local server Example 2:Here we will try to access the text in the first Google search result. To do this, we first select the DOM component that has the first result, as requested by Google. Here we select a span tag that has a class ’ kCrYT ’ from the DOM, which has a list of details for all the queries found, but we only need the first one, so the loop only repeats once.
    • PHP code:this code will work if you’ve already searched for something on Google. include ( ’simple_html_dom.php ’ ); $html = file_get_html ( http://www.google.com/search?q= . $_ POST [ " search " ]); foreach ( $html -> find ( ’ div.kCrYT ’ ) as $elements ) { echo $elements -> plaintext; break ; }
      ?>
    • Exit:
       GeeksforGeeks is a very fast-growing community among programmers and have a reach of around 10 million + readers globally. Writing will surely enhance your knowledge of the subject as before writing any topic, you need to be very crisp and clear about it. 

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method