如何从其他站点获取HTML代码源

问题描述 投票:-1回答:1

如何获取要启用cookie的其他网站的HTML代码?我只需要解析这个页面www.fx-trend.com/pamm/rating/

我正在使用javascript jquery(jQMobile),有时使用PHP。(我更喜欢使用js)

这是一个PHP示例:

<?php
$url = 'url';
$html = file_get_html($url);
//$html = file_get_contents($url);
echo $html;
?>

这是js:How to get data with JavaScript from another server?的示例

要么

$(this).load(url);
alert($(this)); //returns object Object

服务器答案:

必须在浏览器中启用Cookie!如果启用了cookie,请尝试清除所有cookie。

代码样本是受欢迎的。

javascript php jquery html html-parsing
1个回答
2
投票

尝试使用Curl并启用cookie。下面的代码示例来自this page

<?php
/* STEP 1. let’s create a cookie file */
$ckfile = tempnam ("/tmp", "CURLCOOKIE");

/* STEP 2. visit the homepage to set the cookie properly */
$ch = curl_init ("url");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$output = curl_exec ($ch);

var_dump($output);

编辑:您可能必须通过更改默认用户代理标头来伪造浏览器。

© www.soinside.com 2019 - 2024. All rights reserved.