Python 读取原始文本的第一行
嘿,我正在使用我的小刮刀,我想用一个细节保存结果,即原始粘贴箱/任何其他垃圾箱网页的第一行 假设我有以下代码:Python 读取原始文本的第一行,python,python-3.x,web-scraping,python-requests,pastebin,Python,Python 3.x,Web Scraping,Python Requests,Pastebin,嘿,我正在使用我的小刮刀,我想用一个细节保存结果,即原始粘贴箱/任何其他垃圾箱网页的第一行 假设我有以下代码: r=requests.get("https://pastebin.com/raw/qH03hKGU") #random link text=r.text 我想在不保存的情况下获取变量文本的第一行(我只保存一行)您可以使用分区('\n')[0]获取第一行: import requests r=requests.get("https://pastebin.com/raw/qH03hKG
r=requests.get("https://pastebin.com/raw/qH03hKGU") #random link
text=r.text
我想在不保存的情况下获取变量文本的第一行(我只保存一行)您可以使用
分区('\n')[0]
获取第一行:
import requests
r=requests.get("https://pastebin.com/raw/qH03hKGU") #random link
text=r.text
print(text.partition('\n')[0])
OUT: import glob
谢谢,我会在我的很多代码中找到它的用处