[英]Web crawler encounter javascript
我是网络爬虫的新手。 我正在尝试使用Java爬行网页,但是遇到问题。 我需要在href为JavaScript函数的“ HTML标记”中获取链接。 我不知道如何在javascript函数中获取链接。 这是html源和javascript源。
HTML
<a href='javascript:ShowPostGridUnique(205316,0);'>link</a>
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
}
}
}
我如何获得href的链接? 谢谢。
使用像Phantomjs这样的Headless浏览器。 http://phantomjs.org/
使用ghostdriver / selenium控制Phantomjs https://github.com/SeleniumHQ/selenium https://github.com/detro/ghostdriver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.