日期:2014-05-18  浏览次数:20466 次

怎样获取一个网页的html代码?
我能够在A.aspx 中获取B.aspx的html代码,(使用HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);) 

但是怎样能够在获取的同时,传参数到B.aspx.下面的写法实现不了:
string url= "http://localhost:3651/lotteryManager/callCenter/ajaxDataList/UpmanStatus.aspx?fman=" + Fman + "&fstatus=" + Fstatus + "&farea="+Farea;
大家有何办法?


------解决方案--------------------
function InitAjaxTypeListBL()
{
var ajax = null;
try
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
try
{
ajax = new ActiveXObject("Msxml4.XMLHTTP");
}
catch (e)
{
ajax = null;
}
}
if (ajax == null && typeof XMLHttpRequest != 'undefined')
{
ajax = new XMLHttpRequest();
}
return ajax;
}

function NewBLCuoShi()
{
var http_request = InitAjaxTypeListBL();
var url = "TestAjax/BuLiangAjax.aspx?strBLCuoShi="+str;
http_request.open('GET', url, false);
http_request.send(null);

------解决方案--------------------
VB.NET code
 '读取网页
         Dim code As Encoding = Encoding.GetEncoding("utf-8")
        Dim sr As StreamReader = Nothing
        Dim str As String = Nothing
        Dim temp As WebRequest = Nothing
        Dim mytemp As WebResponse = Nothing
        Try
            temp = WebRequest.Create(txturl.Text.Trim())
            mytemp = temp.GetResponse
            '开始读取
            sr = New StreamReader(mytemp.GetResponseStream(), code)
        Catch ex As Exception
            err_notice.Text = "读取文件出错."
            Exit Sub
        End Try

------解决方案--------------------
mark
------解决方案--------------------
string url= "http://localhost:3651/lotteryManager/callCenter/ajaxDataList/UpmanStatus.aspx?fman=" + Fman + "&fstatus=" + Fstatus + "&farea="+Farea; 
请求这个url , 应该是可以的。如果不行的话,看看你的那些变量是什么类型的编码。怀疑是编码的问题。单步调试下,
------解决方案--------------------
我之前做过抓取远程页面的html代码,比你这个复杂多了!我做的是获取UPS\TNT\FEDEX\DHL等8个物流公司网站的html代码,并获取需要的数据入库!

如果你的这个url能在浏览器中直接调出页面来,那你那个方法应该是可以的!如果不行,那可能就是你其他的地方出了问题,你可以单步调试一下!常出现的问题比如编码的问题、已获得数据但读取出来等等。

如果还不行你可以联系我!