如何从Django运行外部脚本?

2024-03-29 13:05:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我要用基本的关键字和django工具来设置表。现在,我想使用外部googlescraper脚本(https://github.com/NikolaiT/GoogleScraper)来分析这些关键字,一旦它们被添加到django的ORM中(google每个关键字并保存前10个结果供以后分析)。在

在django之外运行此脚本很容易:

import sys
from GoogleScraper import scrape_with_config, GoogleSearchError
from GoogleScraper.database import ScraperSearch, SERP, Link

# very basic usage
def basic_usage():
    # See in the config.cfg file for possible values
    config = {
        'SCRAPING': {
...
if __name__ == '__main__':

usage = 'Usage: {} [basic|image]'.format(sys.argv[0])
if len(sys.argv) != 2:
    print(usage)
else:
    arg = sys.argv[1]
    if arg == 'basic':
...

https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

这是最好的办法吗?在

是否有一些类似的脚本在Django中实现的例子,我可以看到并学习到:)?在

干杯


Tags: djangofromhttpsimport脚本comconfigif