【问题标题】:Parser PHP - phpQuery解析器 PHP - phpQuery
【发布时间】:2018-03-03 10:40:46
【问题描述】:

我有一个任务。表on this page contains links。在每个链接for exampple first 中,存在一个带有电子邮件的字段。我必须复制所有这些电子邮件。

我使用 phpQuery 编写脚本。

<?php
    header('Content-type: text/html; charset=utf8');
    require 'phpQuery-onefile.php';

    function parseMail($url){
        $file = file_get_contents($url);
        $doc = phpQuery::newDocument($file);
            foreach ($doc->find('#table_top > tbody > tr')as $tempmail{
                $tempmail = pq($tempmail)
                $mail = $tempmail->find("contains('@')");
                }
    }

    function print_arr($arr){
        echo '<pre>' . print_r($arr, true) . '</pre>';
    }

    $url = 'http://www.topscolibucuresti.ro/bucuresti';
    $file = file_get_contents($url);

    $doc = phpQuery::newDocument($file);

    foreach($doc->find('#table_top > tbody > tr')as $article){
        $article = pq($article);
        $link = $article->find('a')->attr('href');

        parseMail($link);

        print_arr($mail);
    }

脚本显示错误,但我不明白为什么.. 我该怎么办?

【问题讨论】:

  • 嘿伙计,我看到了链接,但在您提供的网站上没有任何电子邮件地址。我错过了什么?
  • 嗨。欢迎来到堆栈溢出。您是否先尝试使用另一个较小的网页来解决问题? (即,您是否尝试过单独重现问题?)查看帮助中心,了解如何编写出色的问题 (stackoverflow.com/help/on-topic)
  • @Jonathon,谢谢.. 我会看看。我没有孤立地尝试。你认为它会有结果吗?
  • @Yitzhak 我需要打开每个链接。在这些页面中存在电子邮件。例如第一个链接:topscolibucuresti.ro/scoala/colegiul-national-gheorghe-lazar
  • @engins:你得到了什么错误?

标签: php phpquery


【解决方案1】:

您收到该错误是因为您错过了一个分号。

    foreach ($doc->find('#table_top > tbody > tr')as $tempmail{
        $tempmail = pq($tempmail)
        $mail = $tempmail->find("contains('@')");

pq($tempmail)后面应该有分号

【讨论】:

  • 谢谢.. 但现在我收到新错误:解析错误:语法错误,意外';'在第 9 行的 C:\OpenServer\domains\parsing\scoli-v1.php 中
  • 您的foreach$tempmail 之后没有右括号
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-02
  • 2011-11-17
  • 2010-12-11
  • 2012-02-12
  • 2014-09-17
相关资源
最近更新 更多