提取HTML数据我想从该网站提取姓名,地址和电子邮件PHP:从网站
http://agentquery.com/agent.aspx?agentid=13
我如何在PHP
做到这一点使用的file_get_contents()对于如
$abc = file_get_content("http://agentquery.com/agent.aspx?agentid=13");
现在,我怎么提取NAME,从中EMAIL和地址?
提取HTML数据我想从该网站提取姓名,地址和电子邮件PHP:从网站
http://agentquery.com/agent.aspx?agentid=13
我如何在PHP
做到这一点使用的file_get_contents()对于如
$abc = file_get_content("http://agentquery.com/agent.aspx?agentid=13");
现在,我怎么提取NAME,从中EMAIL和地址?
这可以用file_get_contents()
和一些正则表达式处理来完成。你必须确保你在php.ini
启用fopen URL wrappers你需要抓住的页面,然后找到唯一的字符串来解析上。这是获得名称:
<?php
$page = file_get_contents('http://agentquery.com/agent.aspx?agentid=13');
// name will be inside a span ctl00_Agent1_lblName, store it in $agent_name
preg_match("/<span id=\"ctl00_Agent1_lblName\".*span>/", $page, $agent_name);
// display agent name matches
print_r($agent_name);
这很简单,你只用简单的HTML DOM类,如果你知道CSS选择器,你可以得到所需要的值,jQuery的
看起来不错,但其给有里面什么都没有了如数组我echod'回声计数($ AGENT_NAME);'计数为零 – Saaram 2013-02-27 07:42:29
得到它..它的ID不CLASS .. – Saaram 2013-02-27 07:46:30
噢,抱歉,刚才编辑我的答案。有这些日子之一... – sjdaws 2013-02-27 07:47:28