简体   繁体   中英

How to get dynamically changing value from external url in PHP?

I'm trying to get a quantity value from external link, but I can't see this value until particular colour or size is selected (selection on that website works using JavaScript void(0) ).

Is it possible to trigger a link somehow and get the value after? Any suggestions?

However I know how to get a static value from url, see below:

 $url = 'http://www.website.com/page.html'; $content = file_get_contents($url); $first_step = explode( '<span id="quantity">' , $content ); $second_step = explode("</span>" , $first_step[1] ); echo $second_step[0]; 

Maybe solution, you can to split the process into two parts :

get all elements with regexp

preg_match_all('/<span [^>]+>/i',$content , $match); 
print_r($match);

search attrs array of the result

$spans = array();
foreach( $match as $tag)
{
    preg_match_all('/(id)=("[^"]*")/i',$tag, $spans[$tag]);
}

print_r($spans);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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