Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Parsing a url for IP address using python

from urllib.parse import urlparse, parse_qs
import socket


url = 'http://example.com/x/y?a=1&b=2'

# Parse the URL
parsed = urlparse('http://example.com/x/y?a=1&b=2&a=3')

# For the parameters
params = parse_qs(parsed.query)
print(params)

# For path components
# Note: Depending on the URL, this may have empty strings so that's why the
# filter is used
path_components = list(filter(bool, parsed.path.split('/')))
print(path_components)

# Location
print(parsed.netloc)

# IP
print(socket.gethostbyname(parsed.netloc))
Comment

PREVIOUS NEXT
Code Example
Python :: rendere eseguibile python 
Python :: Allow Complex Number like "1+2j" to be treated as valid number 
Python :: form is undefined flask 
Python :: computercraft turtle place block 
Python :: ex: python 
Python :: successful=true for number in range (3) print ("Attempt") if successful: print ("Successful") breal 
Python :: is complex datatype immutable in python 
Python :: the grandest staircase of them all foobar solution 
Python :: drop values in column with single frequency 
Python :: numpy.where() for substring 
Python :: machine learning cheatsheet activation function 
Python :: onetoone vs foreign key django 
Python :: organize order columns dataframe 
Python :: Scope, Global Variables and Global Keyword 
Python :: background subtraction params opencv python 
Python :: first n lis tpython 
Python :: numpy substract subsequent elements 
Python :: python keyboard monitoring 
Python :: ValueError: initial_value must be specified. site:stackoverflow.com 
Python :: online python compailer 
Python :: how to check if a dictionary is empty in python 
Python :: numpy np sign change in df pandas zero crossing 
Python :: get maximum values in a column by a subgroup of a dataframe pandas 
Python :: QuizListView login required django 
Python :: python generator for reading and writing file 
Python :: brython implemantation 
Python :: python which __divs__ are there 
Python :: how to add a list to a list python 
Python :: dataset.shape 
Python :: how to comment in python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =