我如何抓取一些由java脚本生成的元数据是源代码我可以看到这里是我的卷曲函数
<head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
<title>Bitcoin Wallet - Coinbase</title>
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="/apple-touch-icon-iphone-114.png" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-iphone-114.png" />
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-ipad-144.png" />
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-ipad-144.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-Frame-Options" content="deny" />
<link href="/assets/application-872c8328f77eafb2d1ace7dbcf51cb1b.css" media="all" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[window.jQuery || document.write(unescape('%3Cscript src="/assets/jquery-056780eda252b4dc226532b22d80dc1a.js" type="text/javascript">%3C/script>'))//]]>
</script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="zqNomg7I3GGiY80OjMAAMG/Lbr76CFuob4iljqMlszU=" name="csrf-token" />
<script type="text/javascript" src="//use.typekit.net/pkh0ghc.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
</head>
这是我需要的部分
<meta content="zqNomg7I3GGiY80OjMAAMG/Lbr76CFuob4iljqMlszU="
我如何使用php curl来实现这一点是我目前的curl脚本我可以添加什么来完成这个
<?php
$url = "https://coinbase.com/";
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $url);
curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($h, CURLOPT_HEADER, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($h, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($h, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, "utf8=%E2%9C%93&authenticity_token=".$csrf_token."&user%5Bemail%5D=example@outlook.com&user%5Bpassword%5D=examplepw&commit=Create+My+Account");
$result = curl_exec($h);
$tmp = preg_replace('!" name="csrf-token" />.*!s', '', $result);
$csrf_token = preg_replace('!.*"!s', '', $tmp);
print $csrf_token . "\n";
?>
答案 0 :(得分:0)
有点不同的方法:
<?php
$url = "https://coinbase.com/";
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $url);
curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);
#curl_setopt($h, CURLOPT_HEADER, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($h, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($h, CURLOPT_FOLLOWLOCATION, false);
$result = curl_exec($h);
$tmp = preg_replace('!" name="csrf-token" />.*!s', '', $result);
$csrf_token = preg_replace('!.*"!s', '', $tmp);
print $csrf_token . "\n";
?>