我想从网站中提取姓名,地址和电子邮件
http://agentquery.com/agent.aspx?agentid=13
如何使用file_get_contents()在PHP
例如
$abc = file_get_content("http://agentquery.com/agent.aspx?agentid=13");
现在我如何提取名称,电子邮件和地址从它?
这可以用file_get_contents()
和一些正则表达式处理来完成。你必须确保在PHP.ini
您需要抓取页面,然后找到要解析的唯一字符串。这是为了获取名称:
<?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中的选择器
http://simplehtmldom.sourceforge.net/