PHP:从网站中提取 HTML 数据 [英] PHP: Extract HTML data from website
问题描述
我想从网站中提取 NAME、ADDRESS 和 EMAIL
I want to to extract NAME, ADDRESS and EMAIL from the website
http://agentquery.com/agent.aspx?agentid=13
如何在 PHP 中使用 file_get_contents() 执行此操作
How can I do this using file_get_contents() in PHP
例如
$abc = file_get_content("http://agentquery.com/agent.aspx?agentid=13");
现在如何从中提取姓名、电子邮件和地址?
Now how can I extract NAME, EMAIL and ADDRESS from it ?
推荐答案
这可以通过 file_get_contents()
和一些正则表达式处理来完成.您必须确保在 PHP.ini 中启用了 fopen URL 包装器
This can be done with file_get_contents()
and some regex processing. You must ensure you have fopen URL wrappers enabled in PHP.ini
您需要抓取页面,然后找到要解析的唯一字符串.这是为了取名字:
You need to grab the page, then find unique string to parse on. This is to get the name:
<?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);
这篇关于PHP:从网站中提取 HTML 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!