简体   繁体   English

如何等待我的脚本使用 PHP Simple HTML DOM Parser 加载页面?

[英]How do I wait for my script to load the page with PHP Simple HTML DOM Parser?

I'm making a call to a website where they have a javascript loading code.我正在调用一个网站,在那里他们有一个 javascript 加载代码。 When I launch the script I only collect the data that is already loaded but it doesn't wait for it to load the whole page.当我启动脚本时,我只收集已经加载的数据,但不会等待它加载整个页面。

I try to collect the data shown in some div to make a statistic in my backend from the web of trivago, which has a loader in the.我尝试收集某个 div 中显示的数据,以便在我的后端从 trivago 的 web 中进行统计,该 web 中有一个加载器。 To do this I launch the following code:为此,我启动了以下代码:

include_once('simple_html_dom.php');

function getHTML($url,$timeout){
  $ch = curl_init($url); // initialize curl with given url
  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTPS_USER_AGENT"]); // set  
  useragent
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
  curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
  return @curl_exec($ch);
}

$html = file_get_html("https://www.trivago.es/?aDateRange%5Barr%5D=13-04-2019&aDateRange%5Bdep%5D=14-04-2019&iPathId=82650&iGeoDistanceItem=0&aCategoryRange=0%2C1%2C2%2C3%2C4%2C5&aOverallLiking=1%2C2%2C3%2C4%2C5&sOrderBy=relevance%20desc&iRoomType=7&cpt=8265003&iViewType=0&bIsSeoPage=false&bIsSitemap=false&");

I try to collect the data with the find() function:我尝试使用 find() 函数收集数据:

foreach($html->find("div.item__flex-column") as $seccion) {
  echo "<tr>";
    echo "<td>";
      echo $seccion->find("h3",0)->plaintext;
    echo "</td>";
    echo "<td>";
      echo $seccion->find("p.details__paragraph",0)->plaintext;
    echo "</td>";
    echo "<td>";
      echo $seccion->find("strong.item__best-price",0)->plaintext; 
    echo "</td>";
    echo "<td style='text-decoration:line-through;'>";
      echo $seccion->find($fmp,0)->plaintext; 
    echo "</td>";
  echo "</tr>";
}

And the mistake I get:我得到的错误是:

Fatal error: Uncaught Error: Call to a member function find() on string致命错误:未捕获的错误:在字符串上调用成员函数 find()

Is there any way to stop the PHP program until it loads the whole page?有没有办法停止 PHP 程序直到它加载整个页面?

尝试

echo $seccion->find("h3")[0]->plaintext;

我怎么找到最后一个<div class>在带有 PHP 简单 HTML DOM 解析器的 HTML 文件中?</div><div id="text_translate"><p> 根据<a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">SIMPLE HTML DOM PARSER</a>的文档(在“How to modify HTML Elements”选项卡下),这段代码找到了<div class="hello">的第一个实例:</p><pre> $html = str_get_html('<div class="hello">Hello</div><div class="world">World</div>'); $html->find('div[class=hello]', 0)->innertext = 'foo'; echo $html; // Output: <div class="hello">foo</div><div class="world">World</div></pre><p> 如果我想在<div class="hello">的<em>最后一个</em>实例中插入 'foo' 怎么办,假设 HTML 代码有很多<div class="hello">实例。</p><p> 什么应该取代0 ?</p></div> - How do I find the last <div class> in an HTML File with PHP Simple HTML DOM Parser?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎么找到这个div? (PHP Simple HTML DOM Parser) - How do I find this div ? (PHP Simple HTML DOM Parser) 如何使用PHP Simple HTML DOM Parser来解析它? - How do I use the PHP Simple HTML DOM Parser to parse this? 如何使用PHP Simple DOM Parser等待iFrame加载 - How to wait for iFrame to load using PHP Simple DOM Parser PHP简单html dom解析器-简单脚本 - PHP simple html dom Parser - Simple Script 我怎么找到最后一个<div class>在带有 PHP 简单 HTML DOM 解析器的 HTML 文件中?</div><div id="text_translate"><p> 根据<a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">SIMPLE HTML DOM PARSER</a>的文档(在“How to modify HTML Elements”选项卡下),这段代码找到了<div class="hello">的第一个实例:</p><pre> $html = str_get_html('<div class="hello">Hello</div><div class="world">World</div>'); $html->find('div[class=hello]', 0)->innertext = 'foo'; echo $html; // Output: <div class="hello">foo</div><div class="world">World</div></pre><p> 如果我想在<div class="hello">的<em>最后一个</em>实例中插入 'foo' 怎么办,假设 HTML 代码有很多<div class="hello">实例。</p><p> 什么应该取代0 ?</p></div> - How do I find the last <div class> in an HTML File with PHP Simple HTML DOM Parser? 如何在简单HTML DOM解析器中选择externalHTML - How do I select outerHTML in Simple HTML DOM Parser PHP简单HTML DOM解析器:我想使用php简单dom解析器将javascript链接添加到html dom - PHP Simple HTML DOM Parser: I want to add javascript link to html dom with php simple dom parser 如何通过简单的html dom解析器在php中解析 - how to parse this by simple html dom parser in php PHP:Simple DOM Parser如何迭代这个html - PHP : Simple DOM Parser how to iterate this html PHP简单HTML DOM解析器 - PHP Simple HTML DOM parser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM