简体   繁体   English

PHP-从完全加载的外部页面加载HTML

[英]PHP - Load HTML from a fully loaded external page

I'm new to AJAX and php and have been trying to figure out how use a PHP HTML DOM Parser to fetch the html from an external site. 我是AJAX和php的新手,并且一直在尝试弄清楚如何使用PHP HTML DOM解析器从外部站点获取html。 However, the html fetched is the one immediately loaded into DOM and I require elements which are included later on in the page via Javascript. 但是,获取的html是立即加载到DOM中的html,我需要通过Javascript包含在页面稍后的元素。 How do I fetch the latter with PHP. 如何使用PHP提取后者。

Example: When I use my parser to load: http://csgo.exchange/id/76561198078821986 the big numerical value in the h3 tag on the left is "0.00" because the h3 tag is loaded into dom with a value of "0.00" and later modified to its real value via Javascript. 示例:当我使用解析器加载时: http : //csgo.exchange/id/76561198078821986左侧h3标签中的大数值是“ 0.00”,因为h3标签已加载到dom中,值为“ 0.00” ”,后来通过Javascript修改为其实际价值。 How do I fetch the real value? 我如何获取真实价值?

The reason you can't use the PHP Parser on that page is because it doesn't run the javascript, only the HTML. 您无法在该页面上使用PHP解析器的原因是因为它不运行JavaScript,仅运行HTML。

If you insist on getting the data from that page you'll need a headless browser like PhantomJS 如果您坚持要从该页面获取数据,则需要一个无头浏览器,如PhantomJS

Otherwise the way to get the data is to find where the javascript is getting it from and pass the same variables. 否则,获取数据的方法是查找javascript从何处获取数据并传递相同的变量。

In your case it's: http://csgo.exchange/inventory/76561198078821986/retry/ 您的情况是: http : //csgo.exchange/inventory/76561198078821986/retry/

You can now parse this URL with the PHP HTML Parser instead and get the values you need. 现在,您可以改为使用PHP HTML Parser解析此URL,并获取所需的值。

A good rule to keep is to always try to find the data in it's rawest form either as html or json . 保持良好的规则是始终尝试以htmljson的原始格式查找数据。 Chrome's network tab is your best friend. Chrome的“网络”标签是您最好的朋友。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM