我试图得到一个HTML页面的内容,使用此代码:如何从PHP生成的HTML页面获取正文内容?
String malSearch = "http://myanimelist.net/anime.php?letter=" + firstLetter;
URL url = new URL(malSearch);
URLConnection con = url.openConnection();
InputStream in = con.getInputStream();
String encoding = con.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[8192];
int len = 0;
while ((len = in.read(buf)) != -1) {
baos.write(buf, 0, len);
}
String body = new String(baos.toByteArray(), encoding);
它工作正常,但它并没有给我什么,我真正想要的。它给我这个:
<html>
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>
<body style="margin:0px">
<iframe src="/_Incapsula_Resource?CWUDNSAI=9&xinfo=6-122029399-0 0NNN RT(1404149034204 2) q(0 -1 -1 -1) r(0 -1) B12(4,315,0) U1&incident_id=124001330081285077-564449081699338326&edet=12&cinfo=4ee46646c753833e04000000" frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula incident ID: 124001330081285077-564449081699338326</iframe>
</body>
</html>
当它应该给我整个页面(大约800行)。
我认为这是由于这是一个使用PHP的网站,但我并不确定。有人能告诉我如何获得整个HTML内容吗?
这里是我想从内容页:http://myanimelist.net/anime.php?letter=A
为什么使用PHP的网站对HTML有任何不同? –
为什么有人会关心服务器使用生成html的语言?服务器可能会有一群无数的猴子在使用工业OCR系统的打字机上进行数字化输出。你会不会在乎,如果是这样的话?无论如何,你所得到的就是html。 –