且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP:从网站中提取 HTML 数据

更新时间:2022-05-23 09:26:58

这可以通过 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);