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