简体   繁体   English

获取 pastebin 中的单词并将其转换为关键字列表

[英]Get words of a pastebin and turn them into a keyword list

for example I have a raw pastebin: https://pastebin.com/raw/YsgHMTkZ like:例如我有一个原始的 pastebin: https://pastebin.com/raw/YsgHMTkZ像:

word1
word2
word3
word4
word5
word6
...

And I'd just like to put them in a variable like this:我只想把它们放在这样的变量中:

keyword_name = ["word1","word2","word3","word4","word5","word6","..."] keyword_name = ["word1","word2","word3","word4","word5","word6","..."]

Thank you, have a good day.谢谢你,祝你有美好的一天。

Send a GET request with requests , retrieve the contents, split them by spaces.发送带有requestsGET请求,检索内容,用空格分隔它们。 And then split will already return a list for you.然后split将已经为您返回一个列表。

import requests

resp = requests.get('https://pastebin.com/raw/YsgHMTkZ')
result = resp.text.split()
print(result)
# ['word1', 'word2', 'word3', 'word4', 'word5', 'word6', '...']

You could use pandas read_csv() which allows url input as well.您可以使用 pandas read_csv() ,它也允许 url 输入。

import pandas as pd
df = pd.read_csv(r"https://pastebin.com/raw/YsgHMTkZ", header=None)
lst = df.iloc[:,0].to_list()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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