开发者

problem with string manipulation function retrieving URL

开发者 https://www.devze.com 2023-03-21 02:17 出处:网络
i build a simple scraper to get me links from other website my problem now is to getting the link it self not all of the content

i build a simple scraper to get me links from other website my problem now is to getting the link it self not all of the content

<a onclick="javascript:_gaq.push(['_trackEvent','outbound-article','namobile.naughtyamerica.com']);" href="http://www.wwww.com/track/MTA3ODQxLjEyLjQwLjQwLjAuMC4wLjAuMA/freeporn3/lisa_ann6/7535/"><img class="aligncenter size-full" title="Lisa Ann" src="http://www.www.com/upload/source/mfhm/lisawill/lisawillhor_gmna_big_img3.jpg" alt="Lisa Ann" width="313" height="223" /></a>

here the image and开发者_如何转开发 its link i need to get the link only in a variable to be like that

$url = "http://www.wwww.com/track/MTA3ODQxLjEyLjQwLjQwLjAuMC4wLjAuMA/freeporn3/lisa_ann6/7535/";

that its it thank you


Use queryPath, Simple HTML DOM Parser or other PHP libraries for navigating in DOM document


You can use PHP Query library, and attr method if you are familiar with CSS selectors.

<?php 
echo pq('a')->attr('href');


$html = <<< EOF
<a onclick="javascript:_gaq.push(['_trackEvent','outbound-article','namobile.naughtyamerica.com']);" href="http://www.wwww.com/track/MTA3ODQxLjEyLjQwLjQwLjAuMC4wLjAuMA/freeporn3/lisa_ann6/7535/"><img class="aligncenter size-full" title="Lisa Ann" src="http://www.www.com/upload/source/mfhm/lisawill/lisawillhor_gmna_big_img3.jpg" alt="Lisa Ann" width="313" height="223" /></a>
EOF;

preg_match_all('/<a onclick.*?href="(.*?)"/im', $html, $url, PREG_PATTERN_ORDER);
$url = $url[1][0];


echo $url // echo's "http://www.wwww.com/track/MTA3ODQxLjEyLjQwLjQwLjAuMC4wLjAuMA/freeporn3/lisa_ann6/7535/"
0

精彩评论

暂无评论...
验证码 换一张
取 消