使用webbrowser控件來加載網(wǎng)頁,然后再
十年的新河網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都營銷網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整新河建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)從事“新河網(wǎng)站設(shè)計”,“新河網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。
Private
Sub
WebBrowser
1_DocumentCompleted下通過使用WebBrowser1.Document.Body.
InnerHtml
來獲取網(wǎng)頁的源代碼,或使用
WebBrowser1.Document.Body.InnerText來獲取網(wǎng)頁中的文本。之后可以通過字符串控制指令或者
正則表達式
來精確獲取到你所需的數(shù)據(jù)。
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è)置一個值,該值指示是否與
Internet資源建立持久連接。
Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream,
System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是網(wǎng)頁源代碼
使用webbrowser控件來加載網(wǎng)頁,然后再 Private Sub WebBrowser1_DocumentCompleted下通過使用WebBrowser1.Document.Body.InnerHtml 來獲取網(wǎng)頁的源代碼,或使用 WebBrowser1.Document.Body.InnerText來獲取網(wǎng)頁中的文本。之后可以通過字符串控制指令或者正則表達式來精確獲取到你所需的數(shù)據(jù)。
下面這段代碼,是我用來計算每個月存500元進銀行,連續(xù)30年,最后連本帶利能有多少錢。這里面涉及復(fù)利計算。界面中右邊的文本框用來輸出每一次計算的結(jié)果。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
? Dim nianxian As Integer '年限變量
? Dim dingcun As Integer '定存變量
? Dim fuli_big As Long '大復(fù)利
? Dim fuli_small As Long '小復(fù)利
? Dim i As Integer '循環(huán)變量
? Dim DATAstring As String '數(shù)據(jù)字符串
? nianxian = Val(年限_TextBox.Text)
? dingcun = Val(定存_TextBox.Text)
? DATAstring = ""
? For i = 1 To nianxian
? ? ? fuli_small = dingcun * (1 + 0.1875)
? ? ? dingcun = fuli_small
? ? ? fuli_big = fuli_big + fuli_small
? ? ? DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_big) + Chr(13) + Chr(10)
? ? ? 'DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_small) + Chr(13) + Chr(10)
? Next
? 'fuli_big = fuli_small
? TextBox1.Text = DATAstring
? 結(jié)果_TextBox.Text = Str(fuli_big) + "元"
End Sub
Delphi代碼如下:
procedure?TForm1.Button1Click(Sender:?TObject);
var
購物總價:Integer;
折扣:Extended;
begin
購物總價:=StrToInt(Edit1.Text);
if?購物總價250?then
begin
折扣:=0;
end
else?if?購物總價500?then
begin
折扣:=0.05;
end
else?if?購物總價1000?then
begin
折扣:=0.075;
end
else?if?購物總價2000?then
begin
折扣:=0.1;
end
{
此段的折扣是多少?
else?if?購物總價3000?then
begin
折扣:=0.05;
end
}
else?if?購物總價=3000?then
begin
折扣:=0.15;
end;
ShowMessage('您享受的折扣是:'+FloatToStr(折扣)
+'?原價:'+IntToStr(購物總價)
+'?折后總價:'+FloatToStr(購物總價*(1-折扣)));
end;
Dim MyClient As WebClient = New WebClient
Dim MyReader As New System.IO.StreamReader(MyClient.OpenRead(url), System.Text.Encoding.Default) '定義新的文件流并讀取網(wǎng)頁文件數(shù)據(jù),url表示需要打開的網(wǎng)頁地址
Dim longTxt As String = MyReader.ReadToEnd 'longtxt存儲了網(wǎng)頁的源碼
MyReader.Close()