【问题标题】:How to get a certain number of words from a website in python如何从python中的网站获取一定数量的单词
【发布时间】:2021-01-12 10:38:15
【问题描述】:

我想使用 requests 库和 discord.py 库从 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)

【问题讨论】:

  • 使用response.text[:1800]获取response.text中的前1800或更少

标签: python-3.x python-requests urllib discord.py-rewrite


【解决方案1】:
 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)

这将是正确的代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-23
    • 2020-11-15
    • 1970-01-01
    • 2023-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2015-11-26
    相关资源
    最近更新 更多