Hi @lahorimela
The file_get_html
function is a part of the Simple HTML DOM library, which allows you to parse and manipulate HTML documents easily. To add a field to the HTML document you’re fetching with file_get_html
, you’ll need first to load the HTML into a DOM object, make the changes to that object, and then save the modified HTML. Here’s an example of how you might add a new field to the HTML document:
<?php
include ("simple_html_dom.php");
$name = get_post_meta($post->ID, 'company', true);
$html = file_get_html("https://other-website-url.com/company/".$name);
// Find the element you want to add the field to
$element = $html->find('#element-id', 0);
// Create a new field
$field = $html->createElement('input');
// Set the attributes for the field
$field->type = 'text';
$field->name = 'new_field';
// Add the field to the element
$element->appendChild($field);
// Save the modified HTML
$html->save();
// Do something with the modified HTML
echo $html;
?>
This will find the element with the ID of element-id
in the HTML document and append a new input element to it with the name new_field. Please change the element-id to the one you need for the desired result.
You should always check the website’s Terms of Use before scraping any data, as some websites may not allow web scraping.