這個(gè)問(wèn)題有點(diǎn)意思,但題主表意不明,確切的說(shuō)應(yīng)該分Web端和客戶端兩種情況。
在瀘州等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作定制開(kāi)發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),成都營(yíng)銷網(wǎng)站建設(shè),外貿(mào)營(yíng)銷網(wǎng)站建設(shè),瀘州網(wǎng)站建設(shè)費(fèi)用合理。
想來(lái)問(wèn)到這個(gè)問(wèn)題的不應(yīng)該是開(kāi)發(fā)Web端的,說(shuō)說(shuō)客戶端的吧:
1、HttpWebRequest.CookieContainer
Cookies通過(guò)HttpResponse傳給客戶端,通過(guò)HttpRequest傳回服務(wù)端,因此你可以
設(shè)置Response.Cookies集合的值修改Cookie
1
Response.Cookies("MyCookie")("Data") = myCookie
通過(guò)讀取Request.Cookies集合的值得到Cookies的值
1
myCookie =Request.Cookies("MyCookie")("Data") ""
2、本人自編的一個(gè)函數(shù),放到一個(gè)模塊里直接調(diào)用即可:
Dim myCookie As String
Public Function LoginAnGetCookie(ByRef sUser As String, ByRef sPass As String) As String()
On Error Resume Next
REM 登錄網(wǎng)站并獲得cookie
Dim url As String = "網(wǎng)站地址"
Dim postData As String = "sUser=" sUser "sPass=" sPass '假設(shè)傳值的是這樣的,實(shí)際中可用Fiddler抓取。
Dim wc As System.Net.WebClient = New System.Net.WebClient
Rem wc.Headers.Add("Cookie", myCookie) '可講第一次獲得的Cookie賦值給myCookie,然后在此處傳值給網(wǎng)站即可
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
wc.Headers.Add("UserAgent", "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10)")
Dim sHtml As String = wc.UploadString(url, "POST", postData)
Dim arrAllKeys() As String = wc.ResponseHeaders.AllKeys
Dim sCookies As String = "Set-Cookie"
For i As Integer = 0 To arrAllKeys.Length - 1
If arrAllKeys(i).Equals("Set-Cookie") Then sCookies = wc.ResponseHeaders.Get(i)
Next i
Return New String() {sHtml, sCookies} '返回二維數(shù)組,其中LoginAnGetCookie(0)是網(wǎng)頁(yè)源代碼,LoginAnGetCookie(1)是登錄后的Cookie
End Function
這個(gè)用到庫(kù)的問(wèn)題(是matlab庫(kù))
開(kāi)頭:
#include mex.h/*這個(gè)matlab自己的也是必須的*/
庫(kù)函數(shù)(4個(gè)參數(shù))//名字忘了太長(zhǎng)了
{
//自己的程序;
}
使用webbrowser控件來(lái)加載網(wǎng)頁(yè),然后再
Private
Sub
WebBrowser
1_DocumentCompleted下通過(guò)使用WebBrowser1.Document.Body.
InnerHtml
來(lái)獲取網(wǎng)頁(yè)的源代碼,或使用
WebBrowser1.Document.Body.InnerText來(lái)獲取網(wǎng)頁(yè)中的文本。之后可以通過(guò)字符串控制指令或者
正則表達(dá)式
來(lái)精確獲取到你所需的數(shù)據(jù)。
Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String
'啟動(dòng)一次具體的數(shù)據(jù)采集工作,返回采集到的HTML內(nèi)容:要求必須輸入帶://的全地址數(shù)據(jù)
On Error Resume Next
Dim Str_WebContent As String = "請(qǐng)輸入查找網(wǎng)站地址."
Dim wb As WebClient = New WebClient() '//創(chuàng)建一個(gè)WebClient實(shí)例
If mWebsiteUrl.IndexOf("://") 0 Then
'//獲取或設(shè)置用于對(duì)向 Internet 資源的請(qǐng)求進(jìn)行身份驗(yàn)證的網(wǎng)絡(luò)憑據(jù)。(可有可無(wú))
wb.Credentials = CredentialCache.DefaultCredentials
'//從資源下載數(shù)據(jù)并返回字節(jié)數(shù)組。(加@是因?yàn)榫W(wǎng)址中間有"/"符號(hào))
Dim pagedata As Object = wb.DownloadData(mWebsiteUrl)
'//轉(zhuǎn)換字符
If mWebsiteType Then
Str_WebContent = Encoding.Default.GetString(pagedata)
Else
Str_WebContent = Encoding.UTF8.GetString(pagedata)
End If
End If
Return Str_WebContent '提取出來(lái)新聞內(nèi)容,刪除Body前后的多余內(nèi)容,同時(shí)補(bǔ)充上該 Body標(biāo)記,形成完整的內(nèi)容 Str_WebContent '
End Function
Dim url As String=" 網(wǎng)址"
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpReq.Method = "GET"
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = False ' 獲取或設(shè)置一個(gè)值,該值指示是否與
Internet資源建立持久連接。
Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream,
System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是網(wǎng)頁(yè)源代碼