-
Notifications
You must be signed in to change notification settings - Fork 0
/
stocknewsfeed.php
47 lines (42 loc) · 1.08 KB
/
stocknewsfeed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
require "vendor/autoload.php";
use Goutte\Client;
$client = new Client();
$crawler = $client->request('GET', 'https://www.marketscreener.com/news/markets/');
$list=array();
$crawler->filter('td.newsColCT > a')->each(function ($node) use (&$list) {
// print $node->text()."<br>";
$list['name'][]=trim($node->text());
$list['url'][]=trim('https://www.marketscreener.com'.$node->attr('href'));
});
$count=0;
$newlist=array();
foreach($list['url'] as $url){
if($count<=15){
$crawler = $client->request('GET', $url);
$imgx='';
$crawler->filter('span.clearfix div img')->each(function ($node) use (&$imgx) {
// print $node->text()."<br>";
if($imgx==''){
$imgx=trim($node->attr('src'));
}
});
$newlist['img'][]=$imgx;
}else{
break;
}
$count++;
}
$refinelist=array();
$xc=0;
foreach($newlist['img'] as $img){
$refinelist['img'][]=$img;
$refinelist['name'][]=$list['name'][$xc];
$refinelist['url'][]=$list['url'][$xc];
$xc++;
}
header('Content-type: application/json');
echo json_encode(array('data'=>$refinelist));
?>