首页 > 解决方案 > 在内存中加载 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()

标签: pythonpython-requests

解决方案


推荐阅读