PHP Getting text/value from a span by id and put it in a variable from an external site with cURL
13,126
To work with $_POST
data, you actually have to post the content, typically in a form. The only way to do what you want is to fetch and extract the data from the HTML file itself. (file_get_contents
and curl
may come in handy at this point)
Finally, you're going to have to parse and extract the data from your obtained content. There are a handful of ways you could do this including using a regular expression or by working directly with the Document Object Model (DOM). (I prefer the latter method.)
Author by
Jordy144
Updated on June 25, 2022Comments
-
Jordy144 almost 2 years
My question is, how do I get the value/text by id, thats between a span from an external website by using cURL. And after that, put it in a variable.
I have the following span:
<span id="company" class="company">Example</span>
I tried to use:
$company = $_POST['company']; echo($company);
But that didn't work.
The output should be:
Example
-
Jordy144 over 10 yearsHi Carson, thanks for your reply. I am using curl, sorry for not mentioning it. The span is from an external website.
-
Jordy144 over 10 yearsHi Louis, thanks for your reply. Yes I am using curl. I want to get the text/value from a span that's on an external website.
-
Carson Myers over 10 yearsWhoops, didn't see that. In that case go with Louis' answer - and take his advice and use a DOM parser, don't use regular expressions (see this: stackoverflow.com/a/1732454/84478)
-
Julio over 10 yearsSo
curl
the page's content, and parse out the data by working with the DOM.