What is the python equivalent of "urllib2" on a point network?

I am new to python. I want to create a bot in C #. Can I use this "urllib2" on a point network or is there an alternative to a point network? please, help...

+3
source share
3 answers

Most of the equivalent functionality is in the System.Web namespace:

The System.Web namespace provides classes and interfaces that provide interaction between the browser and the server. This namespace includes the HttpRequest class, which provides extensive information about the current HTTP request; The HttpResponse class, which controls the HTTP output to the client; and the HttpServerUtility class, which provides access to server-side utilities and processes. System.Web also includes classes for manipulating cookies, passing files, exception information, and managing the output cache.

A close cousin urlopenis the System.Net.Webclient class:

Provides common methods for sending data and retrieving data from a resource identified by a URI.

using System;
using System.Net;
using System.IO;

public class Test
{
    public static void Main (string[] args)
    {
        if (args == null || args.Length == 0)
        {
            throw new ApplicationException ("Specify the URI of the resource to retrieve.");
        }
        WebClient client = new WebClient ();

        // Add a user agent header in case the 
        // requested URI contains a query.

        client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

        Stream data = client.OpenRead (args[0]);
        StreamReader reader = new StreamReader (data);
        string s = reader.ReadToEnd ();
        Console.WriteLine (s);
        data.Close ();
        reader.Close ();
    }
}
+4
source

HttpRequest / WebClient. sockets. , .

, .NET python IronPython. python .NET.


/ , , , , .

+2
0
source

Source: https://habr.com/ru/post/1714043/


All Articles