Download a web page

From IronPython Cookbook

(Difference between revisions)
(Using the WebClient class)
Line 1: Line 1:
-
== Using the WebClient class ==
+
Hi, I am Anjila Wilson and.I am resident of United States. I love music and net surfing. I got some health related
-
A simple example:
+
informations from some articles.You can see from this link
-
<pre>
+
-
from System.Net import WebClient
+
-
content = WebClient().DownloadString("http://google.com")
+
-
print content
+
-
</pre>
+
-
There are other useful shortcuts as well. For example, to download a 'page' (or resource) from the internet and save it as a file, you can use the [http://msdn2.microsoft.com/en-us/library/system.net.webclient.downloadfile.aspx WebClient.DownloadFile] method:
 
-
<pre>
 
-
from System.Net import WebClient
 
-
WebClient().DownloadFile(url, filename)
 
-
</pre>
 
-
 
+
[http://www.acaiberryinformations.com acai berry supplement]
-
The longer way, that is more flexible if you want to configure the [http://msdn2.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx WebClient] class, is:
+
[http://www.articlesbase.com/supplements-and-vitamins-articles/my-weight-loss-experience-with-the-acai-berry-diet-1726693.html Acai Berry]
-
 
+
[http://ezinearticles.com/?Acai-Berry---How-I-Lost-30-Pounds-in-Under-30-Days-Using-The-Acai-Berry&id=1998407 Acai Berry]
-
<pre>
+
[http://www.buzzle.com/articles/the-facts-and-half-truths-about-the-acai-berry-diet.html Acai Berry]
-
from System.Net import WebClient
+
-
from System.IO import StreamReader
+
-
 
+
-
client = WebClient()
+
-
dataStream = client.OpenRead('http://google.com')
+
-
reader = StreamReader(dataStream)
+
-
result = reader.ReadToEnd()
+
-
print result
+
-
</pre>
+
-
 
+
-
== Using the WebRequest and WebResponse classes ==
+
-
<pre>
+
-
from System.Net import WebRequest
+
-
request = WebRequest.Create("http://google.com")
+
-
response = request.GetResponse()
+
-
responseStream = response.GetResponseStream()
+
-
from System.IO import StreamReader
+
-
result = StreamReader(responseStream).ReadToEnd()
+
-
print result
+
-
</pre>
+
-
 
+
-
For a convenience function, which works whether you are making a 'POST' or a 'GET', see [[Submit a POST form and download the result web page]].
+
-
 
+
-
 
+
-
Back to [[Contents]].
+

Revision as of 05:30, 15 October 2010

Hi, I am Anjila Wilson and.I am resident of United States. I love music and net surfing. I got some health related

informations from some articles.You can see from this link


acai berry supplement Acai Berry Acai Berry Acai Berry

TOOLBOX
LANGUAGES