parse text between b(bold) tag
i am trying to log into my hulkshare account, and then return my account information. The curl login is workfine but i dnt think my parsing is working because when i use var_dump($tag) it returns array(0) { }
I am trying to parse the points in my account and here is the code fro the table located between a bold tag < b>6302.00 downloads< /b>
<div id="content-wrap">
<div id="wrap-in">
<br>
<table>
<tbody><tr><td>Username:</td><td><b></b></td><td></td></tr>
<tr><td>You have collected:</td><td><b>6302.00 downloads</b></td><td><input type="button" class="btn2" value="Convert downloads" onclick="document.location='?op=convert_points'"></td></tr>
<tr><td>Used space:</td><td><b>354.0 of 200000 Mb</b></td></tr>
<tr><td>My published files link:</td><td colspan="2"><a href="" target="_blank"></a></td></tr>
<tr><td>My affiliate link:</td><td colspan="2"><a href=""></a><br><small>New user will get 10 downloads</small></td></tr>
</tbody></table>
$cook开发者_如何学Goiefile = '/temp/cookies.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.hulkshare.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'op=login&redirect=&login=XXXXXX&password=XXXXX');
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, 'http://hulkshare.com/?op=my_account');
$contents = curl_exec($ch);
curl_close($ch);
//parse
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument();
$dom->loadHTML($contents);
$xml = simplexml_import_dom($dom);
libxml_use_internal_errors(FALSE);
$tag = $xml->xpath("/table/tbody/tr/tb/b");
var_dump($tag);
If there are multiple things you want to extract from a page, then it's advisable to use a library like phpQuery or QueryPath wich allows for a much simplified:
foreach (qp($html)->find("b") as $b) print $b->text();
But in your case you should head straight for text extraction. You have a very clear pattern and a page that is unlikely to change a lot. Use a regex. HTML tags make nice anchors, but you actually only had to look for the decimals before "download":
preg_match('#<b>([\d.]+) downloads#i', $html, $match);
$downloads = $match[1];
精彩评论