首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用php simple html dom获取javascript值?

如何使用php simple html dom获取javascript值?
EN

Stack Overflow用户
提问于 2018-10-20 05:23:23
回答 1查看 704关注 0票数 0

我使用的是Simple HTML DOM http://simplehtmldom.sourceforge.net/

代码语言:javascript
复制
?php

include_once('simple_html_dom.php');

$content = file_get_html('https://www.mesemix.hu/hu/superman-ruhanemuk/11292-szuperhosoek-mintas-zokni.html')->plaintext;

echo $content;
?>

问题是,我试图抓取的webshop中有一些包含重要值的javascript,我需要这样:

代码语言:javascript
复制
var productReference = 'SP- 418070';

This is the webshop's source.

有没有人知道如何获得"SP- 418070“的明文也?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-20 05:27:36

你要做的事情是:

转到他们的商店,然后按F12,然后单击"Elements tab",您可以看到其中的所有代码。您要查找的模型的选择器是:

代码语言:javascript
复制
.product_reference .editable

如果您需要查找某些内容,只需使用搜索菜单的ctrl+f。

如果您的代码结构类似于简单HTML dom上的演示版本

代码语言:javascript
复制
$html->find('.product_reference .editable', 0)->innertext;

编辑使用curl,在某个地方运行此代码,您将获得整个web内容

代码语言:javascript
复制
<?php
header('content-type:text/plain');
// define the URL to load
$url = 'example.com'; //THE URL THAT YOU NEED
// start cURL
$ch = curl_init(); 
// tell cURL what the URL is
curl_setopt($ch, CURLOPT_URL, $url); 
// tell cURL that you want the data back from that URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
// run cURL
$output = curl_exec($ch); 
// end the cURL call (this also cleans up memory so it is 
// important)
curl_close($ch);
// display the output
echo $output;
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52900092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档