ivansabik / dom-hunter
工具包,用于通过cURL HTTP请求和DOM爬取创建自定义API
1.0.0
2014-05-28 02:34 UTC
Requires
This package is not auto-updated.
Last update: 2024-09-28 15:39:23 UTC
README
用于探索HTML/文档对象模型(DOM)响应以查找对象的库。它有助于进行内容发现,例如进行网络抓取或从现有Web应用程序构建API。DOM Hunter允许指定在URL或目标HTML代码中要捕获的不同对象。该库包含一个功能库,通常希望在一个HTML响应中找到以构建API(日期、标识符、关键词等)。DOM Hunter使用DOM导航和正则表达式来捕获对象。以下是其工作方式:
- 用户创建一个DOMHunter实例,并指定附加选项,如headers、模拟浏览器/设备、POST/GET请求等。
- 将搜索元素(对象)添加到DOMHunter实例中。
- 调用
hunt()
方法。 - 库向目标发送cURL请求(或可以直接设置包含HTML的字符串)并清理DOM,然后将其分配给对象以搜索对象。
- 获取一个包含指定索引的结果数组的数组。
DOM Hunter不是一个完整的网络抓取器,因为它无法模拟用户的点击、超时等活动。它仅限于搜索响应中的所有文本节点,并使用正则表达式查找元素,即使DOM结构发生变化。
它正在不断变化,因此第一版的使用方式可能会有很大差异。
捕获对象(找到的对象)
- 键值对
- 唯一标识符
- DOM节点
- 表格
- 选择选项
- 图像(暂缺)
适用于Estafeta的示例
$params_peticion = array( 'idioma' => 'es', 'dispatch' => 'doRastreoInternet' 'guias' = '3563581975'; 'tipoGuia' = 'ESTAFETA'; ); $hunter = new DomHunter('http://rastreo3.estafeta.com/RastreoWebInternet/consultaEnvio.do', 1); $hunter->arrParamsPeticion = $params_peticion; $presas = array(); $presas[] = array('numero_guia', new KeyValue('numero de guia')); $presas[] = array('codigo_rastreo', new KeyValue('digo de rastreo')); $presas[] = array('origen', new KeyValue('origen')); $presas[] = array('destino', new KeyValue('destino', TRUE, TRUE)); $presas[] = array('cp_destino', new IdUnico(5, 'num')); $presas[] = array('servicio', new KeyValue('entrega garantizada', FALSE)); $presas[] = array('estatus', new NodoDom(array('find' => '.respuestasazul'), 'plaintext', 1)); $presas[] = array('fecha_recoleccion', new KeyValue('fecha de recoleccion')); $presas[] = array('fecha_programada', new KeyValue('de entrega', TRUE, TRUE)); $presas[] = array('fecha_entrega', new KeyValue('Fecha y hora de entrega')); $presas[] = array('tipo_envio', new KeyValue('tipo de envio')); $presas[] = array('peso', new KeyValue('Peso kg')); $presas[] = array('peso_vol', new KeyValue('Peso volumétrico kg')); $presas[] = array('recibio', new KeyValue('recibi')); $presas[] = array('dimensiones', new KeyValue('Dimensiones cm')); $columnas = array('fecha', 'lugar_movimiento', 'comentarios'); $presas[] = array('historial', new Tabla(array('ocurrencia' => -1), $columnas, 3)); $hunter->arrPresas = $presas; $resultados = $hunter->hunt(); # Arreglo con los resultados, puede ir directísimo a Mongodb
墨西哥邮政示例
墨西哥联邦区交通(违规)示例
$hunter = new DomHunter('http://www.finanzas.df.gob.mx/sma/detallePlaca.php?placa=912TER'); $presas = array(); $presas[] = array('folio', new IdUnico(11, 'num')); $presas[] = array('situacion', new KeyValue('pagada', FALSE)); $presas[] = array('motivo', new KeyValue('Motivo')); $presas[] = array('fundamento', new KeyValue('Fundamento')); $presas[] = array('sancion', new KeyValue('as de salario m', FALSE)); $hunter->arrPresas = $presas; $hunted = $hunter->hunt();
AICM示例
$hunter = new DomHunter('http://www.aicm.com.mx/en/flights?da=a&in=n'); $columnas = array('origin', 'airline', 'flight', 'time', 'status', 'gate', 'terminal'); $presas[] = array('llegadas', new Tabla(array('ocurrencia' => 1), $columnas)); $hunter->arrPresas = $presas; $resultados = $hunter->hunt();
IFAI义务示例(合同)
$hunter = new DomHunter('http://portaltransparencia.gob.mx/pot/contrataciones/consultarContrato.do?method=consultaContrato&id.idContrato=130767&_idDependencia=12220'); $presas = array(); $presas[] = array('sector_presupuestal', new KeyValue('SECTOR PRESUPUESTAL')); $presas[] = array('siglas', new KeyValue('SIGLAS')); $presas[] = array('fecha_actualizacion', new KeyValue('Última fecha de actualizaci')); $presas[] = array('numero_contrato', new KeyValue('mero de Contrato')); $presas[] = array('unidad_administrativa', new KeyValue('Unidad administrativa que celebr')); $presas[] = array('procedimiento_contratacion', new KeyValue('Procedimiento de contrataci')); $presas[] = array('denominacion_asignado', new KeyValue('n social de la persona moral a que se asig')); $presas[] = array('fecha_contrato', new KeyValue('Fecha de celebraci')); $presas[] = array('objeto_contrato', new KeyValue('Objeto de contrato')); $presas[] = array('monto_contrato', new KeyValue('Monto del contrato')); $presas[] = array('moneda', new KeyValue('Tipo de Moneda')); $presas[] = array('fecha_inicio', new KeyValue('Fecha de inicio del contrato')); $presas[] = array('fecha_fin', new KeyValue('Fecha de terminaci')); $presas[] = array('documento', new KeyValue('Documento del Contrato')); $hunter->arrPresas = $presas; $hunted = $hunter->hunt();
政治DNA示例
测试
对于发起请求和解析结果,Dom Hunter基于以下应用程序进行测试:
- Estafeta
- 墨西哥邮政
- 墨西哥联邦区交通
- 墨西哥联邦区机场
- IFAI透明度义务门户
- 政治DNA
在doc/output[NOMBRE_SERVICIO].md
文件中包含请求的完整HTTP headers,以便在需要模拟其他设备、发送cookies和其他header相关技巧时使用。