简体   繁体   English

如何从 pastebin.com 获取句子并将它们放入列表中?

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

So I have this pastebin link here: https://pastebin.com/raw/egumzQZD And I want a way for python to get the sentences in the pastebin link and put it in a list.所以我在这里有这个 pastebin 链接: https ://pastebin.com/raw/egumzQZD 我想要一种让 python 获取 pastebin 链接中的句子并将其放入列表的方法。 Is there any way to do this?有没有办法做到这一点? So for example:例如:

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.'
]

My goal is so that the python code can print a random sentence using:我的目标是让 python 代码可以使用以下方法打印随机句子:

print(random.choice(list))

you need to do web scraping here.你需要在这里做网络抓取 A sample example using requests module使用requests模块的示例

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

print(new_list)

output输出

['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.

相关问题 从pastebin.com使用正则表达式检查并提取关键字 - Check & extract keyword with regex from pastebin.com Python 3.4-从pastebin.com下载新上传的文本文件 - Python 3.4 - Downloading newly uploaded text files from pastebin.com 获取 pastebin 中的单词并将其转换为关键字列表 - Get words of a pastebin and turn them into a keyword list 如何使用Pastebin API将几个字符串放入Pastebin? - How can I take a few strings and put them in Pastebin, using the Pastebin API? 如何使用密码从 Pastebin 获取原始数据? - How to get a raw data from Pastebin with password? 如何仅从字典列表中获取值,然后在Python中再次将它们放在列表中? - How to get only values from a list of dictionary and put them in a list again in Python? 如何使用 SpaCy 从句子列表中获取名词短语 - How to get noun phrases from a list of sentences using SpaCy 如何从键值列表中的句子中搜索关键字,并得到带有相对引用的句子的匹配结果? - How to search keywords from sentences in a key-value list and get the matched result of the sentences with relative references? 将句子放入列表-python - put sentences into list - python 如何从用户那里获取输入,将它们放入列表中,然后从中随机选择一个,而无需多次询问 - How to get input from user, put them into a list and then choose a random one from them without having to ask multiple times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM