nowphp

导航

 
use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;
include './vendor/autoload.php';


$client = new Client();
$crawler = $client->request('GET', 'http://f10.eastmoney.com/f10_v2/CoreConception.aspx?code=sz000005');
//$crawler = $client->click($crawler->selectLink('Sign in')->link());
//$form = $crawler->selectButton('Sign in')->form();
//$crawler = $client->submit($form, array('login' => 'fabpot', 'password' => 'xxxxxx'));
$crawler->filter('.summary')->each(function ($node) {
    print $node->text()."\n";
});
//var_dump($crawler);

 

 

composer require fabpot/goutte

 

匹配两个class

html : <div class=”class1 class2″>
php  : $crawler->filter(‘div.class1.class1’);

匹配id

html : <div id=”hello”>
php  : $crawler->filter(‘div#hello’);

图片

html : <img src=”http://www.lhzcl.com/image.png”>
php  : $crawler->filter(‘img’)->attr(‘src’);

内嵌html

这个我常用来检测匹配规则是否正确

html : <div class=”catchMeIfYouCan”><span id=”hello”>Hello</span>world</div>
php  : $crawler->filter(‘catchMeIfYouCan’)->html();

http://api.symfony.com/3.2/Symfony/Component/DomCrawler/Crawler.html#method_image


雄安新区:http://stock.gtimg.cn/data/get_hs_xls.php?id=pt021323&type=1&metric=chr
posted on 2017-04-20 14:30  不断成长  阅读(201)  评论(0编辑  收藏  举报