Working on a script project, literally spent the last 4 hours on this researching everything I can - my head literally doesn't function anymore on this matter and really need your help. So I have a PHP cURL script that grabs data from a website. I can grab div's that have ID's and all that. But how can I grab specific text from within a DIV that does not have any ID/class/or anything specific other than the fact that its the only bold item in the div? Here is the HTML Text on the website: <div class="firststyle"><label for="calculator" class="class-coll-1"> <p class="sr-only">Welcome to the calculator:</p> <b>What is one plus two?</b> </label></div> HTML: What I am trying to parse/extract from this HTML part is JUST the text "What is one plus two?". How can define this specific part to be selected? The only thing I can currently do is parse the entire div with the following script: $html = str_get_html($response); $the_question = $html->find('div[class=firststyle]'); PHP: However this gets all the text including the "Welcome to the calculator" label thing which I don't need. Would it be possible to maybe somehow save the parsed data into a variable, and then go from that use a different script to extract the data from that variable? Or maybe can I do something like: Find div with this ID -> find bold text within it Or maybe: Find div with ID -> get everything but the text "Welcome to calculator"
This seems to work: <?php include 'simple_html_dom.php'; $response = '<div class="firststyle"><label for="calculator" class="class-coll-1"> <p class="sr-only">Welcome to the calculator:</p> <b>What is one plus two?</b> </label></div>'; $html = str_get_html($response); echo $the_question = $html->find('.class-coll-1',0)->children(1); ?> PHP: Never really used Simple HTML DOM before, this took me about 5 minutes, including downloading it, reading the manual, and making a test-file...
Thanks for the reply. Tried this method, the scripted works when you put the html as the $response variable but for some reason didn't work when I tried to grab the html from the webpage. However, what did work is the following script: $html->find('.firststyle b',0)