[英]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.