python - 在内存中加载 requests.get().text?
问题描述
我正在制作一些东西,我去一个 url(我的 url),从网站 use 抓取行.text.splitlines()
。但是,我希望我的程序经常这样做,并且我不希望它每次都继续发出请求(我有超过一百万个请求)。是否可以将页面的内容存储到内存中?
我的代码:
import random, requests
country_list = requests.get("url")
ending = requests.get("url")
presets = [""]
def generate_shopping():
shopping_begin = requests.get("url")
shopping_words = requests.get("url")
return random.choice(shopping_begin.text.splitlines()) + "-" + random.choice(shopping_words.text.splitlines()) + "-" + random.choice(country_list.text.splitlines()) + "-" + random.choice(presets) + "-" + random.choice(ending.text.splitlines())
def output():
with open("outputs.txt", "w", encoding='utf8') as f:
for i in range(1000000):
f.write(generate_shopping() + "\n")
output()
解决方案
推荐阅读
- laravel - 在 Laravel SQLite 的现有表中添加 NOT NULL 列
- python - 我怎样才能返回 1 else 0
- android-studio - 如何处理loggedInUser 身份验证和撤销身份验证?
- r - 获取数据框中列的名称时出错
- c# - C# 命令行参数
- flutter - Flutter Tabs 需要引导到同一页面的不同部分
- vue.js - v-autocomplete watcher 没有按预期工作
- firebase - Firestore 安全规则 - 它的真正用途是什么?
- react-native - npx pod-install 返回“此项目不支持 CocoaPods”
- node.js - 电子 4+ 中加密模块的 createECDH 不支持 secp256k1