如何阅读网页HTML页面? [英] how to read web html page ?

查看:91
本文介绍了如何阅读网页HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个网站获取(读取)数据

我想从
读取数据
http://whatismyipaddress.com/ip/101.2.50.106 [

i want to fetch(read) data from another website

i want to read data from

http://whatismyipaddress.com/ip/101.2.50.106[^]

input is ip address
using Query String like
http://whatismyipaddress.com/ip/txtIp.Text

from this page i want

General IP Information and Geolocation Information

i want it in a html format

how can i read...
help me ...
thanks

推荐答案

这将从该页面获取HTML内容,但CSS,样式和任何其他动态效果都不会下载.玩这个.


This will get the HTML content from that page but the CSS, styling and any other dynamic effects will not be downloaded. Play around with this.


<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://www.sehajpal.com",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Result HTML goes here.</h2></div>
<button type="button"  önclick="loadXMLDoc()">Fetch HTML</button>
</body>
</html>


如果要从c#下载网页,请使用WebClient class:

If you want to download a webpage from c#, use the WebClient class:

WebClient client  = new WebClient();
var content = client.DownloadString("http://whatismyipaddress.com/ip/101.2.50.106");
 //here you have the page downloaded int he the 'content' variable



WebClient 类还有其他可以帮助您的方法.



The WebClient class have other methods that can help you.


这篇关于如何阅读网页HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆