導航:首頁 > 編程語言 > 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相關的資料

熱點內容
手機時間如何校正到伺服器 瀏覽:81
創造與魔法瞬移源碼百度 瀏覽:882
反射優化java 瀏覽:874
硬體加密播放盒子 瀏覽:923
xp點擊文件夾選項沒反應 瀏覽:537
蘋果不顯示桌面的app怎麼刪除 瀏覽:864
安卓手機怎麼換國際服 瀏覽:415
神獸領域安卓怎麼下載 瀏覽:250
單片機交通燈ad原理圖 瀏覽:413
多功能解壓磁鐵筆 瀏覽:80
少兒編程火箭升空 瀏覽:401
蘭斯10游戲解壓碼 瀏覽:42
手機proxy伺服器地址 瀏覽:449
吉他清音壓縮 瀏覽:301
簡歷模板程序員 瀏覽:882
螺桿壓縮機虛標型號 瀏覽:953
idea開發項目伺服器ip地址 瀏覽:125
串口伺服器出現亂碼怎麼解決 瀏覽:950
命令按鈕的default 瀏覽:161
戰網如何登錄其他伺服器 瀏覽:990