[問題] 關於模組函式

看板Python作者 (QQ)時間7年前 (2017/01/01 03:59), 7年前編輯推噓0(009)
留言9則, 4人參與, 最新討論串1/1
import requests url='http://xxx.xxx.xx' html= requests.get(url).text.splitlines() 我知道get()作用 不過那是書上有寫的到,我試著去看requests模組下get()的code,看不出它是可以取得 網頁內容的東西。 requests模組下還有其他用法requests.xxx() 我要如何知道它還有哪些,並且功能是什麼? 上方requests.get(url) 後面接text.splitlines() 我知道requests.get() 接的原因 書上有寫它的作用,但是我不知道text.splitlines()為什麼可以這樣接,這函式在哪。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.72.106.139 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1483214366.A.A92.html

01/01 04:25, , 1F
估狗requests 就有很多用法可以參考了 .text就是其一
01/01 04:25, 1F

01/01 04:26, , 2F
str.splitlines() 是字串內建的方法 詳請可看官方文檔
01/01 04:26, 2F
※ 編輯: a82 (211.72.106.139), 01/01/2017 04:44:25

01/01 13:55, , 3F
help(requests) ; s = 'str' ; help(str)
01/01 13:55, 3F

01/01 13:56, , 4F
(s)
01/01 13:56, 4F

01/01 14:01, , 5F
你搞錯了 requests.get(url) 會吐回一個物件
01/01 14:01, 5F

01/01 14:02, , 6F
這個物件下的 text 屬性,類型是内建的 str 型別
01/01 14:02, 6F

01/01 14:03, , 7F
所以 .splitlines 是呼叫這個 str 物件的 method
01/01 14:03, 7F

01/01 14:03, , 8F
簡單來說就是他其實和 requests 沒有關係
01/01 14:03, 8F

01/02 22:24, , 9F
type(東東)跑出它是什麼;dir(東東)跑出它有什麼;
01/02 22:24, 9F
文章代碼(AID): #1OQ0uUgI (Python)