導航:首頁 > 編程語言 > pythonurl

pythonurl

發布時間:2022-01-17 00:53:28

python3 如何對url解碼實現Python2中urllib.unquote的作用

url編碼:

import urllib

url = 'http://test.com/s?wd=哈哈' #如果此網站編碼是gbk的話,需要進行解碼,從gbk解碼成unicode,再從Unicode編碼編碼為utf-8格式。

url = url.decode('gbk', 'replace')

print urllib.quote(url.encode('utf-8', 'replace'))

㈡ python編寫介面,請求url應該如何確定

1、是一個介面
2、程序需要運行後才能訪問,可以部署到伺服器上,程序一旦運行是守護進程,只要不關閉程序一直會運行
3、請求的url根據'/xxx'來確定,請求的類型 methods=['get']

㈢ python urllib2.urlopen(url).read()亂碼

ubuntu 的控制台默認是utf8編碼的吧。而且這個google返回的是big5編碼嗎,用下面的代碼解碼下試試

url="網址"
content = urllib2.urlopen(url).read()
print content.decode('big5').encode('utf8')

㈣ 如何用python訪問URL

import urllib2

req = urllib2.urlopen(url)
print req.read()

㈤ python 如何獲取url信息

importweb

defmake_text(string):
returnstring

urls=('/','tutorial')
render=web.template.render('templates/')

app=web.application(urls,globals())

my_form=web.form.Form(
web.form.Textbox('',class_='textfield',id='textfield'),
)

classtutorial:
defGET(self):
form=my_form()
returnrender.tutorial(form,"Yourtextgoeshere.")

defPOST(self):
form=my_form()
form.validates()
s=form.value['textfield']
returnmake_text(s)

if__name__=='__main__':
app.run()

㈥ 關於python urlopen函數

python
3裡面,bytes存放的是binary
data,而str存放的text
從bytes轉到str,需要把binary
data解碼,因此你需要指定一個編碼,例如:
my_str
=
str(my_bytes,
encoding="utf-8")
建議閱讀文檔:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
http://docs.python.org/release/3.0.1/howto/unicode.html#unicode-howto
這兩段文檔應該足夠解決你的困惑,呵呵

㈦ Python如何下載請求的url指向文件,例如這樣的: http://edi.chi/Print.dofileId=123

#!/usr/bin/envpython
#-*-coding:utf-8-*-
importrequests

print('start')
url=r'問號前面的網址'
parms={
'fileId':'123'
}
try:
r=requests.post(url,data=parms)
print(r.text)
exceptExceptionase:
print(e)

㈧ python url提取

importre
text='<ahref="/Enterprise/GeneralWorkerDetails/3553297586.html"class="clearfix">'
p=re.compile("<ahref="(.*?)"");
match=p.match(text)
printmatch.group(1)

㈨ python中url太長怎麼解決

今天寫了個腳本 主要就是實現利用SQLInj點直接把數據獲取到本地並存到Mysql資料庫中
學過Python的都知道可以使用urllib2中的request()方法直接打開Url,但僅限於url後沒有跟復雜的參數串
今天我利用的Url是
' and (select top 1 cast(CONTENT as varchar(8000)) from xxx.dbo.xxx where cast(CONTENT as varchar) not in (select top 22 cast(CONTENT as varchar) from xxx.dbo.xxx))=0--
開始我也直接用以下語句測試的:
url="上面的URL"
req=urllib2.Request(url)
urllib2.urlopen(req)
可是執行後一直提示500錯誤,由此可以發現應該是Python在對Url進行編碼的時候更改了某些特殊字元造成Url失效
我們可以用urllib2或urllib的quote()方法控制對特殊字元的URL編碼,這里推薦用 urllib下的quote_plus()方法,它將空格轉化成'+'而非%20通用性更好。
我們更改後的代碼如下:
url = "' and (select top 1 cast(CONTENT as varchar(8000)) from xxx.dbo.xxx where cast(CONTENT as varchar) not in (select top "+str(count)+" cast(CONTENT as varchar) from xxx.dbo.xxx))=0--"
quoteUrl=urllib.quote_plus(url,safe=':\'/?&=()')
fd = urllib.urlopen(quoteUrl)
這樣我們就可以正常的提取數據了

㈩ 關於python的urlopen

python 3裡面,bytes存放的是binary data,而str存放的text

從bytes轉到str,需要把binary data解碼,因此你需要指定一個編碼,例如:
my_str = str(my_bytes, encoding="utf-8")

建議閱讀文檔:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
http://docs.python.org/release/3.0.1/howto/unicode.html#unicode-howto

這兩段文檔應該足夠解決你的困惑,呵呵

閱讀全文

與pythonurl相關的資料

熱點內容
php社區程序 瀏覽:976
python現在就業怎麼樣 瀏覽:304
php上傳目錄許可權設置 瀏覽:736
php合同檔案管理系統 瀏覽:366
tshock伺服器地址 瀏覽:877
php解析文件流 瀏覽:780
伺服器機箱銅片有什麼用 瀏覽:969
樂視手機如何使用原生態安卓 瀏覽:215
dns伺服器怎麼備份啊 瀏覽:865
蘋果退款app怎麼重新購買 瀏覽:655
U盤cmd檢查文件夾成文件 瀏覽:66
java路徑是否存在 瀏覽:338
新氧app上怎麼測臉型 瀏覽:787
用指令獲得命令方塊 瀏覽:427
流星蝴蝶劍怎麼輸入命令 瀏覽:681
keil有紅叉但是能編譯通過 瀏覽:498
賽拉圖的空調壓縮機多少錢 瀏覽:330
linux54 瀏覽:986
shutdown命令linux 瀏覽:250
編譯的輸入 瀏覽:511