English 中文(简体)
PHP 下载网页源代码并搜索特定字符串的脚本
原标题:PHP Script to download a webpage s source code and search for a specific string
  • 时间:2012-05-25 17:22:41
  •  标签:
  • php

我需要帮助 设计一个PHP代码 实现以下目标:

  1. Access a website (www.example.com)
  2. Download its source code into a string variable
  3. 搜索此指定字符串以查找特定内容,例如

基本上我需要搜索 title=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

谢谢大家

问题回答

您可以使用"http://php.net/manual/en/class.domdocument.php" rel=“nofollow”>PHPDOM :

$text = file_get_contents( http://example.com/path/to/file.html );
$doc = new DOMDocument( 1.0 );
$doc->loadHTML($text);
foreach($doc->getElementsByTagName( div ) AS $div) {
    $class = $div->getAttribute( class );
    if(strpos($class,  news ) !== FALSE) {
        if($div->getAttribute( title ) ==  news alert ) {
            echo  title found ;
        }
        else {
            echo  title not found ;
        }
    }
}

http://api.querypath. org/docs/"rel="nofollow"\\\\\ uery path , 试图模仿 jQuery 服务器侧面 :

$text = file_get_contents( http://example.com/path/to/file.html );
if(qp($text)->find( div.news[title="news alert"] )->is( * )) {
    echo( title found );
}
else {
    echo( title found );
}

您可以使用“http://www.php.net/manual/en/class.domxpath.php' rel = “no follow” >DOMXPath 来找到它:

$dcmnt = new DOMDocument(); $dcmnt->loadHTML( $cntnt );
$xpath = new DOMXPath( $dcmnt );
$match = $xpath->query("//div[@title= news alert ]");

echo $match->length ? "Found" : "Not Found" ;

说明:"http://codepad.org/CLDE8XCQ" rel=“no follow'>http://codpad.org/CLDE8XC/a>

这很简单:

$html = file_get_contents( http://site.com/page.html );
if (strpos($html, title="news alert" )!==false)
 echo  title found ;
$page = file_get_contents( http://www.example.com/ );
if(strpos($page, "title="news alert"")!==false){
    echo  title found ;
}
$url =  http://www.example.com/ ;
$page = file_get_contents($url);

if(strpos($page,  title="news alert" ) !==false || strpos($page,  title= news alert  ) !==false)
{
    echo  website with news alert found ;
}
else
{
    echo  website not found ;
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...