[問題] Python3 request問題

看板Python作者 (兩頭尖尖這麼大個)時間7年前 (2018/01/22 14:57), 7年前編輯推噓2(2012)
留言14則, 5人參與, 7年前最新討論串1/1
大家好~~ 我的程式碼非常容易,但是實在找不到問題,想請大大們幫忙 這段程式碼如下 這段程式碼可以使用 import requests req = requests.session() req.get('http://mis.twse.com.tw/stock/index.jsp') # get cookie response = req.get('http://mis.twse.com.tw/stock/api/getStockInfo.jsp?_=1516602174329&ex_ch=tse_2330.tw') print(response.text) 但是我將程式碼第四行,更換成 response = req.get('http://mis.twse.com.tw/stock/api/getStockInfo.jsp?_=1516602174329&ex_ch=tse_2330.tw|tse_1101.tw') 也就是網址列最後方多加了"|tse_1101.tw"之後便不能夠使用了... 想請問大大們是不是因為符號"|"的問題呢? 以及該如何解決? BTW,這兩個網址,我用瀏覽器載入都是沒有問題的,不知道大大們有遇到這種問題過嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.123.122.127 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1516604272.A.280.html ※ 編輯: GGHOWIN (140.123.122.127), 01/22/2018 15:01:47 ※ 編輯: GGHOWIN (140.123.122.127), 01/22/2018 15:04:20 ※ 編輯: GGHOWIN (140.123.122.127), 01/22/2018 15:05:38

01/22 15:47, 7年前 , 1F
? 後面那些要 urllib.quote() , | 是特殊字元
01/22 15:47, 1F

01/22 17:04, 7年前 , 2F
urlencoding?
01/22 17:04, 2F

01/22 17:18, 7年前 , 3F
感謝回應,但是urllib.quote()事了好久,'|'轉換成'%7c'
01/22 17:18, 3F

01/22 17:19, 7年前 , 4F
但是還是不能夠使用,將結果貼致網址列也是不能使用
01/22 17:19, 4F

01/22 17:20, 7年前 , 5F
程度太差了T.T
01/22 17:20, 5F

01/23 00:11, 7年前 , 6F
你是不是順便也quote到其他字元了?
01/23 00:11, 6F

01/23 09:06, 7年前 , 7F
我猜想ex_ch應該是多值欄位吧,譬如多選欄位,試看看用
01/23 09:06, 7F

01/23 09:07, 7年前 , 8F
半形逗號","試試
01/23 09:07, 8F

01/23 09:45, 7年前 , 9F
剛剛測試可以跑: https://pastebin.com/Q2jfaSiw
01/23 09:45, 9F

01/24 13:53, 7年前 , 10F
歹勢,又打擾了,是不是因為我Python3的問題呢? 這是我的
01/24 13:53, 10F

01/24 13:54, 7年前 , 11F
結果,https://imgur.com/a/K6vpE,response2.text回傳
01/24 13:54, 11F

01/24 13:54, 7年前 , 12F
一堆空白,應該是沒有request到的關係。
01/24 13:54, 12F

01/24 14:02, 7年前 , 13F
搞定了!因為時間需要調整到今天,真的可以用!謝謝K大
01/24 14:02, 13F

01/24 14:02, 7年前 , 14F
太開心了!
01/24 14:02, 14F
文章代碼(AID): #1QPOjmA0 (Python)
文章代碼(AID): #1QPOjmA0 (Python)