登录internetsite和下载文件 [英] Logon internetsite and download file

查看:49
本文介绍了登录internetsite和下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨,,


任何人都可以告诉我如何使用用户名和

密码登录互联网网站,导航到该网站上的其他子页面,然后开始下载

a文本文件到磁盘??


谢谢

解决方案

< blockquote>这是我去年写的网络蜘蛛的剪辑:

< snip>

私有函数getHtml(ByVal i As Integer)As String


Dim url As String =" http://www.wtng.info/wtng-" &安培; Chr(i)& Chr(i)&

" .html"

Dim reader As StreamReader

Dim html As String


尝试

reader =新StreamReader(_

CType(_

CType(_

) WebRequest.Create(url),_

HttpWebRequest)。GetResponse(),_

HttpWebResponse).GetResponseStream())


html = reader.ReadToEnd()

reader.Close()


Catch ex As Exception

尝试:reader.Close ():Catch exc As Exception:结束尝试

html =""

Console.WriteLine(无法连接到& url)

结束尝试


返回html.Trim()


结束功能

< / snip>


-

Peace&快乐的计算,

Mike Labosh,MCSD

Musha ring dum a doo dum a da! - 詹姆斯赫特菲尔德

" Henrik" <他**** @ discussions.microsoft.com>在消息中写道

news:70 ********************************** @ microsof t.com ...



任何人都可以告诉我如何使用用户名和密码登录互联网网站,导航到其他子页面在那个网站上,然后开始下载
一个文本文件到磁盘?

谢谢



这是我去年写的网络蜘蛛的剪辑:

< snip>

私函数getHtml(ByVal i As Integer)As String


Dim url As String =" http://www.wtng.info/wtng-" &安培; Chr(i)& Chr(i)&

" .html"

Dim reader As StreamReader

Dim html As String


尝试

reader =新StreamReader(_

CType(_

CType(_

) WebRequest.Create(url),_

HttpWebRequest)。GetResponse(),_

HttpWebResponse).GetResponseStream())


html = reader.ReadToEnd()

reader.Close()


Catch ex As Exception

尝试:reader.Close ():Catch exc As Exception:结束尝试

html =""

Console.WriteLine(无法连接到& url)

结束尝试


返回html.Trim()


结束功能

< / snip>


-

Peace&快乐的计算,

Mike Labosh,MCSD

Musha ring dum a doo dum a da! - 詹姆斯赫特菲尔德

" Henrik" <他**** @ discussions.microsoft.com>在消息中写道

news:70 ********************************** @ microsof t.com ...



任何人都可以告诉我如何使用用户名和密码登录互联网网站,导航到其他子页面在那个网站上,然后开始下载
一个文本文件到磁盘?

谢谢



"亨利克" <他**** @ discussions.microsoft.com> schrieb:

任何人都可以告诉我如何使用用户名和密码登录互联网网站,导航到该网站上的其他子页面,然后开始
下载文本文件到磁盘??




\\\

Dim w As New WebClient()

w.Credentials = New NetworkCredential(" username"," password")

w.DownloadFile(...)

///


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://classicvb.org/petition/>


Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start downloading
a textfile to disk??

Thanks

解决方案

Here''s a snip from a web spider I wrote last year:
<snip>
Private Function getHtml(ByVal i As Integer) As String

Dim url As String = "http://www.wtng.info/wtng-" & Chr(i) & Chr(i) &
".html"
Dim reader As StreamReader
Dim html As String

Try
reader = New StreamReader( _
CType( _
CType( _
WebRequest.Create(url), _
HttpWebRequest).GetResponse(), _
HttpWebResponse).GetResponseStream())

html = reader.ReadToEnd()
reader.Close()

Catch ex As Exception
Try: reader.Close(): Catch exc As Exception: End Try
html = ""
Console.WriteLine("Could not connect to " & url)
End Try

Return html.Trim()

End Function
</snip>

--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
"Henrik" <He****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...

Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??

Thanks



Here''s a snip from a web spider I wrote last year:
<snip>
Private Function getHtml(ByVal i As Integer) As String

Dim url As String = "http://www.wtng.info/wtng-" & Chr(i) & Chr(i) &
".html"
Dim reader As StreamReader
Dim html As String

Try
reader = New StreamReader( _
CType( _
CType( _
WebRequest.Create(url), _
HttpWebRequest).GetResponse(), _
HttpWebResponse).GetResponseStream())

html = reader.ReadToEnd()
reader.Close()

Catch ex As Exception
Try: reader.Close(): Catch exc As Exception: End Try
html = ""
Console.WriteLine("Could not connect to " & url)
End Try

Return html.Trim()

End Function
</snip>

--
Peace & happy computing,

Mike Labosh, MCSD
"Musha ring dum a doo dum a da!" -- James Hetfield
"Henrik" <He****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...

Hi,,

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??

Thanks



"Henrik" <He****@discussions.microsoft.com> schrieb:

Can anyone tell me how to log on to a internet website with username and
password, navigate to other subpages on that site, and then start
downloading
a textfile to disk??



\\\
Dim w As New WebClient()
w.Credentials = New NetworkCredential("username", "password")
w.DownloadFile(...)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


这篇关于登录internetsite和下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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