简体   繁体   English

Web搜寻器遇到JavaScript

[英]Web crawler encounter javascript

I'm new to web crawling. 我是网络爬虫的新手。 I am trying to crawl a webpage using java and I encounter a problem. 我正在尝试使用Java爬行网页,但是遇到问题。 I need to get the link in a 'HTML Tag' whose href is a javascript function. 我需要在href为JavaScript函数的“ HTML标记”中获取链接。 I have no idea how to get the link in the javascript function. 我不知道如何在javascript函数中获取链接。 Here is the html source and javascript source. 这是html源和javascript源。

HTML HTML

<a href='javascript:ShowPostGridUnique(205316,0);'>link</a>

JS ShowPostGridUnique JS ShowPostGridUnique

function ShowPostGridUnique(parentpostid, pageShow) {
    //alert(parentpostid);
    var divid;
    divid = 'divPostContent' + parentpostid;
    if (document.getElementById(divid).className == 'divGridShow') {
        document.getElementById(divid).className = 'divGridHide';
        document.getElementById(divid).innerHTML = '';
    }
    else {
        document.getElementById(divid).className = 'divGridShow';
        // call server side method
        PageMethods.divParentInnerHtml( parentpostid, pageShow, CallSuccessShowPost, CallFailedAlert, parentpostid);
        try {
            divid = 'TDtitle' + parentpostid;
            document.getElementById(divid).className = 'TDtitle';
            divid = 'TDPage' + parentpostid;
            document.getElementById(divid).className = 'TDtitle';
        }
        catch (err) {
            //Handle errors here
        }
    }
}

How can i get the link of href? 我如何获得href的链接? Thanks. 谢谢。

  1. Use Headless Browser like Phantomjs. 使用像Phantomjs这样的Headless浏览器。 http://phantomjs.org/ http://phantomjs.org/

  2. Use ghostdriver/selenium to control Phantomjs https://github.com/SeleniumHQ/selenium https://github.com/detro/ghostdriver 使用ghostdriver / selenium控制Phantomjs https://github.com/SeleniumHQ/selenium https://github.com/detro/ghostdriver

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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