如何在python中从网站中获取一定数量的单词



我想使用requests-lib和discord.py lib从cheat.sh获取数据。。。。但由于discord一次只允许发送2000个字符,我只想提取一定数量的单词/数字/换行符,比如1800。我怎么能这么做?

展示我的想法的一个小代码示例

import requests
url = "https://cheat.sh/python/string+annotations" #this gets the docs of string annotation in python
response = requests.get(url)
data = response.text # This gives approximately 2403 words...but i want to get only 1809 words
print(data)
import requests
url = "https://cheat.sh/python/string+annotations" #this gets the docs of string 
annotation in python
response = requests.get(url)
data = response.text[:1800]
print(data)

这将是正确的代码

最新更新