您现在的位置是:主页 > news > 如何做网站发布商品/电商最好卖的十大产品

如何做网站发布商品/电商最好卖的十大产品

admin2025/5/12 22:14:31news

简介如何做网站发布商品,电商最好卖的十大产品,长春网站制作小程序,网络营销是什么课程用于在Python中构建URL的库 我需要找到一个库来构建python中的URL,例如: http://subdomain.domain.com?arg1someargument&arg2someotherargument 您建议使用哪个库?为什么? 这种图书馆是否有“最佳”选择? Sergio…

如何做网站发布商品,电商最好卖的十大产品,长春网站制作小程序,网络营销是什么课程用于在Python中构建URL的库 我需要找到一个库来构建python中的URL,例如: http://subdomain.domain.com?arg1someargument&arg2someotherargument 您建议使用哪个库?为什么? 这种图书馆是否有“最佳”选择? Sergio…

用于在Python中构建URL的库

我需要找到一个库来构建python中的URL,例如:

http://subdomain.domain.com?arg1=someargument&arg2=someotherargument

您建议使用哪个库?为什么? 这种图书馆是否有“最佳”选择?

Sergio Ayestarán asked 2020-01-11T01:12:48Z

5个解决方案

48 votes

我将使用Python的urllib,它是一个内置库。

# Python 2:

import urllib

# Python 3:

# import urllib.parse

getVars = {'var1': 'some_data', 'var2': 1337}

url = 'http://domain.com/somepage/?'

# Python 2:

print(url + urllib.urlencode(getVars))

# Python 3:

# print(url + urllib.parse.urlencode(getVars))

输出:

http://domain.com/somepage/?var2=1337&var1=some_data

chjortlund answered 2020-01-11T01:13:31Z

32 votes

python标准库中的urlparse都是关于构建有效网址的。 检查urlparse的文档

Senthil Kumaran answered 2020-01-11T01:13:06Z

9 votes

这是使用urlparse生成URL的示例。 这提供了向URL添加路径的便利,而不必担心检查斜杠。

import urllib

import urlparse

def build_url(baseurl, path, args_dict):

# Returns a list in the structure of urlparse.ParseResult

url_parts = list(urlparse.urlparse(baseurl))

url_parts[2] = path

url_parts[4] = urllib.urlencode(args_dict)

return urlparse.urlunparse(url_parts)

args = {'arg1': 'value1', 'arg2': 'value2'}

# works with double slash scenario

url1 = build_url('http://www.example.com/', '/somepage/index.html', args)

print(url1)

>>> http://www.example.com/somepage/index.html?arg1=value1&arg2=value2

# works without slash

url2 = build_url('http://www.example.com', 'somepage/index.html', args)

print(url2)

>>> http://www.example.com/somepage/index.html?arg1=value1&arg2=value2

Michael Jaison G answered 2020-01-11T01:13:51Z

6 votes

import urllib

def make_url(base_url , *res, **params):

url = base_url

for r in res:

url = '{}/{}'.format(url, r)

if params:

url = '{}?{}'.format(url, urllib.urlencode(params))

return url

>>>print make_url('http://example.com', 'user', 'ivan', aloholic='true', age=18)

http://example.com/user/ivan?age=18&aloholic=true

Mike K answered 2020-01-11T01:14:07Z

5 votes

import requests

payload = {'key1':'value1', 'key2':'value2'}

response = requests.get('http://fireoff/getdata', params=payload)

print response.url

印刷品:     [http:// fireoff / getdata?key1 = value1&key2 = value2]

user2275693 answered 2020-01-11T01:14:27Z