簡體   English   中英

如何從 pastebin.com 獲取句子並將它們放入列表中?

[英]How to get sentences from pastebin.com and put them into a list?

所以我在這里有這個 pastebin 鏈接: https ://pastebin.com/raw/egumzQZD 我想要一種讓 python 獲取 pastebin 鏈接中的句子並將其放入列表的方法。 有沒有辦法做到這一點? 例如:

list = [
'This is a sentence.',
'This is another sentence.',
'Oh look! Here\'s another sentence!',
'My... my... Another one.',
'Dear god.... -sigh- here\'s another one.',
'I might stop here.'
]

我的目標是讓 python 代碼可以使用以下方法打印隨機句子:

print(random.choice(list))

你需要在這里做網絡抓取 使用requests模塊的示例

import requests
data = requests.get("https://pastebin.com/raw/egumzQZD")
new_list = data.text.split("\r\n")

print(new_list)

輸出

['This is a sentence.', 'This is another sentence.', "Oh look! Here's another sentence!", 'My... my... Another one.', "Dear god.... -sigh- here's another one.", 'I might stop here.']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM