【发布时间】:2020-01-04 17:23:10
【问题描述】:
我需要抓取我(房地产)客户的旧网站,以便将数据保存在我创建的新网站中。
使用 curl。
深两层。索引页面,然后是属性详细信息页面。
在索引页面中,我需要 curl 来获取页数,因此我的脚本的下一部分可以深入研究所有这些页面并获取每个属性的所有属性数据。
在第一个函数中(parseURL)我需要获取页数
/* This function does the initial parsing to get the number of pages */
public function parseURL($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
// bring back all the html of the page
// echo "csp=$curl_scraped_page";
$data = str_replace(array("\n", "\r"), "", preg_replace('/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', "", $curl_scraped_page));
curl_close($ch);
$regex = '#<div style="float:right;width:540px"><h3 style="margin-top:0px">(.*)</h3><h4>(.*)</h4>(.*)<div style="padding:5px"><a href="(.*)">(.*)</a></div></div>#siU';
// $regex = '#<div class="propertyListLinks"><a href="(.*)">(.*)</a></div#siU';
preg_match_all($regex, $data, $this->details);
$regex2 = '#[[0-9]{1,4}]#';
// echo "<br />data=\n$data<br />";
preg_match_all($regex2, $data, $this->pagination);
// exit;
}
很久以前为我写的,我不记得正则表达式在做什么,我想了解这一点,以便我可以开发它以满足我当前的需求。
请给我建议:
-
#在$regex和$regex2字符串中做了什么? -
siU在$regex字符串末尾的含义是什么?
【问题讨论】:
标签: php curl web-scraping