【问题标题】:Web crawler encounter javascript网络爬虫遇到javascript
【发布时间】:2015-08-11 08:24:49
【问题描述】:

我是网络爬虫的新手。我正在尝试使用 java 抓取网页,但遇到了问题。我需要在其href 是javascript 函数的“HTML 标记”中获取链接。我不知道如何在 javascript 函数中获取链接。这里是html源码和javascript源码。

HTML

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

JSShowPostGridUnique

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
        }
    }
}

如何获取href的链接?谢谢。

【问题讨论】:

    标签: javascript java html web-crawler


    【解决方案1】:
    1. 使用像 Phantomjs 这样的无头浏览器。 http://phantomjs.org/

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

    【讨论】:

    • 谢谢,但我需要使用 Java
    猜你喜欢
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多