How can I use Perl to grab text from a web page that is dynamically generated with JavaScript?

后端 未结 5 1794
时光说笑
时光说笑 2020-12-03 03:39

There is a website I am trying to pull information from in Perl, however the section of the page I need is being generated using javascript so all you see in the source is:<

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 04:23

    You'll need to reverse-engineer what the Javascript is doing. Does it fire off an AJAX request to populate the

    ? If so, it should be pretty easy to sniff the request using Firebug and then duplicate it with LWP::UserAgent or WWW::Mechanize to get the information.

    If the Javascript is just doing pure DOM manipulation, then that means the data must exist somewhere else in the page or the Javascript already. So figure out where it's coming from and grab it.

    Finally, if none of those options are adequate, you may need to just use a real browser to do it. There are a few options for automating browser behavior, like WWW::Mechanize::Firefox or Win32::IE::Mechanize.

提交回复
热议问题