0

as the title suggests, I would like to retrieve links that have a specific class. I have the code to connect to the pages and with the preg_match function I would like to take only the url that is in href = "url".

the structure of the link I would like to take and the one found in href = "", this link is in a table and can also have other attributes but not id, only the view class.

<a title="viwe" class="view" href="link">blablabla</a>

while I wrote this code

$curl = curl_init('http://prove/prove/pag/test.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 = '/<a.*?>(.*?)<\/a>/';
if ( preg_match($regex, $page, $list) )
    echo $list[0];
else
    print "Not found";
fraielito
  • 3
  • 5

1 Answers1

-1

Well, the method you are trying to implement is not recommended, yet if you have to, this expression might be closer to what you have in mind, that I'm guessing:

<a\s.*?\sclass="\s*view\s*"[^>]*>.*?<\/a>

Demo

Emma
  • 27,428
  • 11
  • 44
  • 69
  • ah I understand, why? And what would be the most suitable method? use for example PHP Simple HTML DOM Parser – fraielito Aug 31 '19 at 07:33