简体   繁体   English

使用php使用Loop进行卷曲

[英]Curl with Loop using php

I have a problem, I want to get data from another website and display it on my website using cURL. 我有问题,我想从另一个网站获取数据并使用cURL将其显示在我的网站上。

For example, this is data from the other website which I would like to parse and display on my website. 例如,这是我想解析并显示在我的网站上的其他网站的数据。

<div class="users-name"> <a href='#'>User 1</a></div>
<div class="users-name"> <a href='#'>User 2</a></div>
<div class="users-name"> <a href='#'>User 3</a></div>
<div class="users-name"> <a href='#'>User 4</a></div>
<div class="users-name"> <a href='#'>User 5</a></div>
<div class="users-name"> <a href='#'>User 6</a></div>
<div class="users-name"> <a href='#'>User 7</a></div>
<div class="users-name"> <a href='#'>User 8</a></div>

Currently I'm getting first row of data, but now I want to get all of this data. 目前,我正在获取第一行数据,但是现在我想获取所有这些数据。
I have tried this so far: 到目前为止,我已经尝试过了:

$curl = curl_init('www.domain.com/search.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$page = curl_exec($curl);

if(curl_errno($curl)) // check for execution errors
{
    echo 'Scraper error: ' . curl_error($curl);
    exit;
}

curl_close($curl);

$regex = '/<div class="users-name">(.*?)<\/div>/s';

if(preg_match($regex, $page, $list))
    print_r($list[0]);
else
    print "Not found";

Replace 更换

preg_match($regex, $page, $list)

with

preg_match_all($regex, $page, $list)

preg_match stops after the first match. 在第一个比赛之后preg_match停止。 preg_match_all gets all the matches. preg_match_all获取所有匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM