简体   繁体   中英

DOM HTML & JS scrape from JS part

I want to scrape links from one page to another with HTML DOM pharser.

The other webpage has this code :

$('#vidabc-fast-watch-button').click(function() {
  $('#fast-watch-frame').attr('src','http://vidabc.com/embed-8fyiakzp0ob8.html');
});                     
$('#kingvid-fast-watch-button').click(function() {

  $('#vidwatch-fast-watch-button').click(function() {
    $('#fast-watch-frame').attr('src','');
  });
  $('#estream-fast-watch-button').click(function() {
    $('#fast-watch-frame').attr('src','http://estream.to/embed-2605th4kkypl.html');
  });
  $('#openload-fast-watch-button').click(function() {
    $('#fast-watch-frame').attr('src','http://openload.co/embed/YsaOx8K5Bk0/');
  });

I want to scrape information to another PHP page and preg_match the url. But couldn't find links inside JS code.

Any idea?

You could match the URLs inside the script by looking at the text content of the script tag, and launch a preg_match_all on it:

$scr = $doc->getElementsByTagName('script')[0]->textContent;
preg_match_all("/http:[\w#\[\]@!$&()*+,;=%:\/.?~-]*/", $scr, $urls);

print_r($urls[0]);

For the given example this would output:

Array
(
    [0] => http://vidabc.com/embed-8fyiakzp0ob8.html
    [1] => http://estream.to/embed-2605th4kkypl.html
    [2] => http://openload.co/embed/YsaOx8K5Bk0/
)

See it run on eval.in

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