这是为我写一些基本的Web抓取工具的第一次尝试。我遇到了一个问题,该页面在加载后会运行一些javascript并以此创建表,但是当我使用“ requests”和/或“ BeautifulSoup”时,我会得到一个页面,然后再运行javascript来创建一些表,因此我得到的结果是没有表格。
<script type="text/javascript">
var doReload = "cacheVersion1";
// ARRIS ADD BEGIN Handle Error messages.
window.onerror = function(sMsg,sUrl,sLine){
$.logError("Error msg:"+sMsg + " ["+sUrl+":"+sLine+"]");
// Make sure all unauthorized exception will be handled.
if (sMsg.indexOf("unauthorized") != -1){
handleError("unauthorized");
}
}
// ARRIS ADD END
check_ConType();
if(!isLoggedIn()){
check_PreLoginData();
}
var skin = getSkin();
$.log("Skin=" + skin);
if (skin){
$("#skin_css").attr("href", "skins/"+skin+"/css/global.css?ver=9.1.1802.613");
$.cachedScript("skins/"+skin+"/js/base.js?ver=9.1.1802.613");
}
function menu() {
var m = [{ id:"Home", page:"home", children:[]},
{ id:"ConnectedDevices", page:"device_connection", children:[]},
{ id: "Modem", page:"modem_settings", children:[]},
{ id:"AdvancedSettings", page:null, children:[
{ id:"Wireless", children: [
{ id:"WirelessSignal", page:"wifi_radio" },
{ id:"WirelessSecurity", page:"wifi_settings" },
{ id:"WirelessGuest", page:"guest_settings" },
{ id:"WPS", page:"wifi_wps" }
] },
{id:"Security", children: [
{ id:"Firewall", page:"firewall" },
{ id:"MACFiltering", page:"macfilter" },
{ id:"IPFiltering", page:"ipfilter" },
{ id:"PortForwarding", page:"portforwarding" },
{ id:"PortTriggering", page:"porttriggering" },
{ id:"DMZ", page:"security_dmz" }
] },
{ id: "DHCP", page:"dhcp_setting", children:[]},
{ id: "uPnP", page:"upnp_setting", children:[]},
{id:"Tools", children: [
{ id:"NetworkStatus", page:"device_networkstatus" },
{ id:"Ping", page:"tool_ping" },
{ id:"TraceRoute", page:"tool_trace" },
{ id:"MTUSize", page:"tool_mtu" }
]}
]},//END Settings
{ id: "Admin", page:null, children: [
{ id:"ChangePassword", page:"change_password" },
{ id:"ReloadAndReboot", page:"device_reboot" },
{ id:"RemoteAccess", page:"remote_access" },
{ id:"Info", page:"device_status"},
{ id:"Troubleshoot", page:"tool_troubleshoot", display:"wizard", noAuth:true, menuHide:true}
]}
];
return m;
}
我正在尝试从两个表中提取日期,当我右键单击页面“检查元素”时会看到,并且确实看到了这两个表:
我需要提取: [WirelessConnectedDevice] [LanConnectedDevice]
那么,在运行javascript并创建表后如何返回页面,以便我可以解析最终结果并找到我需要的两个表?
答案 0 :(得分:1)
您要剪贴的网站具有JavaScript动态生成的内容。
您有两种选择可以解决此问题
requests
发送该请求,您可以轻松地保存内容。 第二种方法可以节省时间,资源和直截了当。