gpt4 book ai didi

javascript - 如何在显示主要内容之前抓取运行 Javascript 且带有 cookie 检查的网页

转载 作者:行者123 更新时间:2023-11-30 07:41:00 25 4
gpt4 key购买 nike

我正在尝试抓取并解析以下 RSS 提要: http://english.alarabiya.net/.mrss/en/sports.xml

当我在浏览器中打开它时,它会提供我想要解析的普通 RSS 提要。但是当我在 Java 中下载它时,它会显示以下内容:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function getCookie(c_name) { // Local function for getting a cookie value
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");
if (c_start!=-1) {
c_start=c_start + c_name.length + 1;
c_end=document.cookie.indexOf(";", c_start);

if (c_end==-1)
c_end = document.cookie.length;

return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(c_name, value, expiredays) { // Local function for setting a value of a cookie
var exdate = new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/";
}
function getHostUri() {
var loc = document.location;
return loc.toString();
}
setCookie('YPF8827340282Jdskjhfiw_928937459182JAX666', '105.183.123.12', 10);
try {
location.reload(true);
} catch (err1) {
try {
location.reload();
} catch (err2) {
location.href = getHostUri();
}
}
</script>
</head>
<body>
<noscript>This site requires JavaScript and Cookies to be enabled. Please change your browser settings or upgrade your browser.</noscript>
</body>
</html>

我正在使用简单的流读取,这是我的代码:

     try {
URL url = new URL("http://english.alarabiya.net/.mrss/en/sports.xml");
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));

String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

有谁知道如何解析主要的 RSS 内容并使用 cookie 绕过 Javascript 部分吗?或者有什么想法吗?

P.S.:我正在使用 Rome 库来抓取 RSS 提要,但我认为问题超出了其范围。

最佳答案

尝试HtmlUnit库并使用 setJavascriptEnabled(true) 那里

您的问题与 this 类似一个

关于javascript - 如何在显示主要内容之前抓取运行 Javascript 且带有 cookie 检查的网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34699438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com