簡體   English   中英

我想使用 PHP 腳本創建一個爬蟲

[英]I want to create a crawler using PHP script

我想為網站創建一個 PHP 腳本。 我只想從那個鏈接中找出鏈接。 例如,我有http://example.com鏈接,我的爬蟲應該在后台打開該鏈接並找到所有與http://example.com/[any name]/reviews 匹配的鏈接。 我試過正則表達式但不起作用,有人可以幫助我。

<?php
$url="https://clutch.co/it-services";
$contents =file_get_contents($url);
$pattern = "https://clutch.co/profile/".'/^[a-zA-Z ]*$/'."#review";
$pattern = preg_quote($pattern, '/');
if(preg_match_all($pattern, $contents, $matches)){
   echo "Found matches:\n";
   foreach ($matches[0] as $urls) {
    echo $urls;
  }
}
else{
   echo "No matches found";
}
?>

正則表達式模式有一些語法問題:

分隔符/需要在模式之外,並且該模式(“https://”)內的分隔符和特殊字符( . )需要被轉義(“https:\\/\\/”)

所以模式應該是:

/https:\/\/clutch\.co\/profile\/[a-zA-Z ]*#review/

正則表達式小提琴: https : //regex101.com/r/OEUQOU/1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM