simple-html-dom

How to check if a SimpleHTMLDom element does not exist

此生再无相见时 提交于 2019-12-01 20:12:57
SimpleHtmldom can be used to extract the contents of the first element with class description . $html = str_get_html($html); $html->find('.description', 0) However if this class does not exist, PHP will throw an error Trying to get property of non-object I tried if(!isset($html->find('.description', 0))) { echo 'not set'; } and if(!empty($html->find('.description', 0))) { echo 'not set'; } but both gives the error Can't use method return value in write context What is the proper way to check if the element exist? if(($html->find('.description', 0))) { echo 'set'; }else{ echo 'not set'; } http:

how to scrape this with Simple HTML DOM [closed]

给你一囗甜甜゛ 提交于 2019-12-01 14:37:20
I'm trying to use simple html dom to extract elements from a file that looks like this. The file has several tables that look the same class=sometable . Each table has a few <tr class=sometr> . Then inside each tr, I have th that has the title, and a td that has a category. What I want to extract is all titles class=title and their corresponding category number class=category for all table rows in all tables. I've loaded the file in $html . Can someone tell me what I'm supposed to find after that? I've tried even $collection = $html->find('tr'); and did a vardump on the collection but got

how to scrape this with Simple HTML DOM [closed]

时间秒杀一切 提交于 2019-12-01 13:18:28
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I'm trying to use simple html dom to extract elements from a file that looks like this. The file has several tables that look the same class=sometable .

php: Get plain text from html - simplehtmldom or php strip_tags?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 09:35:11
I am looking at getting the plain text from html. Which one should I choose, php strip_tags or simplehtmldom plaintext extraction? One pro for simplehtmldom is support of invalid html, is that sufficient in itself? You should probably use smiplehtmldom for the reason you mentioned and that strip_tags may also leave you non-text elements like javascript or css contained within script/style blocks You would also be able to filter text from elements that aren't displayed (inline style=display:none) That said, if the html is simple enough, then strip_tags may be faster and will accomplish the same

<tbody> glitch in PHP Simple HTML DOM parser

99封情书 提交于 2019-12-01 04:22:36
I'm using PHP Simple HTML DOM Parser to scrape some data of a webshop (also running XAMPP 1.7.2 with PHP5.3.0), and I'm running into problems with <tbody> tag. The structure of the table is, essentialy (details aren't really that important): <table> <thead> <!--text here--> </thead> <tbody> <!--text here--> </tbody> </table> Now, I'm trying to get to the <tbody> section by using code: $element = $html->find('tbody',0)->innertext; It doesn't throw any errors, it just prints nothing out when I try to echo it. I've tested the code on other elements, <thead> , <table> , even something like <span

<tbody> glitch in PHP Simple HTML DOM parser

僤鯓⒐⒋嵵緔 提交于 2019-12-01 02:11:24
问题 I'm using PHP Simple HTML DOM Parser to scrape some data of a webshop (also running XAMPP 1.7.2 with PHP5.3.0), and I'm running into problems with <tbody> tag. The structure of the table is, essentialy (details aren't really that important): <table> <thead> <!--text here--> </thead> <tbody> <!--text here--> </tbody> </table> Now, I'm trying to get to the <tbody> section by using code: $element = $html->find('tbody',0)->innertext; It doesn't throw any errors, it just prints nothing out when I

Character Encoding issue with PHP Simple HTML DOM Parser

你离开我真会死。 提交于 2019-12-01 00:46:54
I am using PHP Simple HTML DOM Parser http://simplehtmldom.sourceforge.net/ to fetch data like Page Title, Meta Description and Meta Tags from other domains and then insert it into database. But I have some issues with encoding. The problem is that I do not get correct characters from those website which is not in English Language. Below is the code: <?php require 'init.php'; $curl = new curl(); $html = new simple_html_dom(); $page = $_GET['page']; $curl_output = $curl->getPage($page); $html->load($curl_output['content']); $meta_title = $html->find('title', 0)->innertext; print $meta_title . "

PHP Command-line scripts are ignoring php.ini and ini_set('memory_limit',…) directives

馋奶兔 提交于 2019-11-30 17:38:04
问题 I am facing the common "Fatal error: Out of memory (allocated 30408704) (tried to allocate 24 bytes)..." PHP Fatal error. Pages served via Apache are not exhibiting this behavior. I've tried the following: Increasing the memory_limit in php.ini to a much larger value. Increasing memory_limit within the script itself via calls to ini_set('memory_limit', -1) , ini_set('memory_limit', '-1') , ini_set('memory_limit', 100000000) , ini_set('memory_limit', '128M') , etc. unset() ing unneeded arrays

PHP Simple HTML DOM Parser: Select only DIVs with multiple classes

百般思念 提交于 2019-11-30 13:05:14
I was searching like mad and found no solution. The problem is simple. Let's say I have 3 DIVs: <div class="class1"> <div class="subclass"> TEXT1 </div> </div> <div class="class2"> <div class="subclass"> TEXT2 </div> </div> <div class="class1 class2"> <div class="subclass"> TEXT3 </div> </div> So, very simple. I just want to find the TEXT3, which has BOTH class1 and class2. Using Simple HTML DOM Parser, I can't seem to get it to work. Here's what I tried: foreach($html->find("[class=class1], [class=class2]") as $item) { $items[] = $item->find('.subclass', 0)->plaintext; } The problem is, with

how to print cells of a table with simple html dom

馋奶兔 提交于 2019-11-30 05:57:13
问题 i have this html code. Im using Simple HTML Dom to parse the data into my own php script. <table> <tr> <td class="header">Name</td> <td class="header">City</td> </tr> <tr> <td class="text">Greg House</td> <td class="text">Century City</td> </tr> <tr> <td class="text">Dexter Morgan</td> <td class="text">Miami</td> </tr> </table> I need to get the text inside the TDs in an array, example: $array[0] = array('Greg House','Century City'); $array[1] = array('Dexter Morgan','Miami'); I've tried