简体   繁体   中英

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. 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:

print(random.choice(list))

you need to do web scraping here. A sample example using requests module

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM