提取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