simple-html-dom

Get text from next tag

╄→尐↘猪︶ㄣ 提交于 2020-01-21 11:43:08
问题 I have a html snippet that looks like this (of course surrounded by other html): <p class="finfot3"><b>Header:</b></p> <p>Text</p> How can I get Text from this? I'm using simple_html_dom, but I can use something else if simple_html_dom can't do this. 回答1: This is untested, but you might be looking for simple_html_doms next_sibling() method. $html->find('p[class=finfot3]')->next_sibling()->innertext() should return the contents of the second <p> element. 回答2: Find the p element with the class.

Problems with multiple attributes while using PHP Simple HTML DOM

a 夏天 提交于 2020-01-16 13:19:21
问题 I use this code for getting elements of left navigation bar: function parseInit($url) { $ch = curl_init(); $timeout = 0; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); return $data; } $data = parseInit("https://www.smile-dental.de

How to combine the data for the same post together?

我与影子孤独终老i 提交于 2020-01-15 10:23:09
问题 I'm getting some posts data from 2 websites, One website has the title, the date, the description and the link, While the other has the title and the image. So I want to add the image to the other posts data if the titles from both websites are identical. Here is what I tried: $articles = []; //Getting Data From 1st Website $rss = simplexml_load_file($website1); foreach ($rss->channel->item as $item) { $post = []; $post['title'] = (string)$item->title; $post['link'] = (string)$item->link;

How to replace all ul and li tag with div using PHP Simple HTML DOM Parser?

☆樱花仙子☆ 提交于 2020-01-15 03:30:08
问题 Ok, I want to create a "website mobilizer" by using PHP Simple HTML DOM Parser. In the present phase, I want to- change all 'ul' and 'li' tag to 'div' tag and change all 'table' elements (e.g. table,tr,td,th) to div. I tried an workaround for the first problem in following way: . $html=new new simple_html_dom(); $html>load_file($sourceurl); $div="div"; foreach ($html->find('ul') as $element) { $element=$div; } It does seem dull, but I'm not being able to find any other solution. I am

Recursion using PHP Simple DOM Parser

最后都变了- 提交于 2020-01-15 03:10:09
问题 For some reason I get recursion while using Simple DOM Parser Library. My HTML is like <div id="root"> <div class="some_div">some text</div> <div class="field_1 misc1"><a href="#">Some text link</a> <strong>15</strong></div> <div class="field_2 misc2"><a href="#">Some text link</a> <strong>25</strong></div> </div> I created PHP script, included single file include_once('simple_html_dom.php'); And I try to get 15 and 25 values from HTML above. But when I run $ret = $html->find('div[id=root]');

Simple HTML DOM gets only 1 element

最后都变了- 提交于 2020-01-07 07:42:12
问题 I'm following a simplified version of the scraping tutorial by NetTuts here, which basically finds all divs with class=preview http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/comment-page-1/#comments This is my code. The problem is that when I count $items I get only 1, so it's getting only the first div with class=preview , not all of them. $articles = array(); $html = new simple_html_dom(); $html->load_file('http://net.tutsplus.com

not able to retrieve direct child elements using Simple HTML DOM

牧云@^-^@ 提交于 2020-01-06 19:54:11
问题 I have an html table like this <table> <tbody> <tr> <td><table> <tbody> <tr class="prdLi"> <td rowspan="2" class="prdNo"><span>310.</span></td> <td colspan="2" class="prdDe" rowspan="2"><span>Pepsi</span></td> </tr> <tr class="prdLi"> <td class="prdAc"><span> 1.5L</span></td> <td><span> </span></td> </tr> </tbody> </table></td> </tr> </tbody> </table> the table is saved as $html I want to select the child elements of the class .prdLi I tried like this: foreach($html->find('tr.prdLi') as $foo)

How to get Content-type using html simple dom?

喜夏-厌秋 提交于 2020-01-06 19:48:10
问题 I tried find('meta[http-equiv="Content-type"]') but it failed to retrieve that information. 回答1: SimpleHTMLDom doesn't use quoted string literals in the selector. It's just elem[attr=value] . And the comparison of value seems to be case-sensitive (there may be a way to make it case-insensitive, but that I don't know)* E.g. require 'simple_html_dom.php'; $html = file_get_html('http://www.google.com/'); // most likely one one element but foreach doesn't hurt foreach( $html->find('meta[http

PHP simple html dom: apache crashes

纵饮孤独 提交于 2020-01-06 15:42:30
问题 I'm using Simple HTML Dom . I'm trying to run the following: (with WAMP) $doc = file_get_html('http://www.scoop.it/t/curate-your-personal-learning-environment?page=3'); $comments = array(); $CommentList = $doc->find('#commentList div[class=commentContainer]'); if (count($CommentList) > 0) var_dump($CommentList); foreach ($CommentList as $comment) { $text = $comment->find('span[class^=author]'); $comments[] = $this::ctrim($text[0]->innertext); } If I comment out the foreach loop, it runs fine.

How can I speed this up?

試著忘記壹切 提交于 2020-01-06 14:59:17
问题 I have a script which I think is pretty basic scraping, call it what you will, but it takes on average at least 6 seconds...is it possible to speed it up? The $date variables are only there for timing the code and don't add anything significant to the time it takes. I have set two timing markers and each is approx 3 seconds between. Example URL below for testing $date = date('m/d/Y h:i:s a', time()); echo "start of timing $date<br /><br />"; include('simple_html_dom.php'); function