简体   繁体   English

满足某些条件时自动运行 python 脚本

[英]Run a python script automatically when certain conditions are met

I have a script for web scraping which basically grabs a story (title, description/summary, and the story text) off a website, which often are in multiple pages, and writes it all to a text file.我有一个用于 web 抓取的脚本,它基本上从网站上抓取一个故事(标题、描述/摘要和故事文本),通常位于多个页面中,并将其全部写入文本文件。

At the moment, I copy a url and run the python script from PyCharm, it gives the result I need.目前,我复制了一个 url 并从 PyCharm 运行 python 脚本,它给出了我需要的结果。

But I want to automate the running the script part so that whenever I copy a url containing certain text (eg website name), it automatically outputs the text file without me needing to run the script every time I copy a url.但是我想自动化运行脚本部分,以便每当我复制包含某些文本(例如网站名称)的 url 时,它会自动输出文本文件,而无需我每次复制 url 时都需要运行脚本。

I don't know any trick to run some code when you just copy some text, but what I would do is to copy and paste the url in a specific text file and have a cron job that runs every minute.当你只是复制一些文本时,我不知道运行一些代码的任何技巧,但我要做的是将 url 复制并粘贴到特定的文本文件中,并有一个每分钟运行的 cron 作业。

The crone job should be running a python scripts that reads your text file (containing the urls) and starts scraping if any url is in there. cron 作业应该运行一个 python 脚本,该脚本读取您的文本文件(包含 url)并在有任何 url 时开始抓取。

See here for cron job details: https://opensource.com/article/17/11/how-use-cron-linux有关 cron 作业的详细信息,请参见此处: https://opensource.com/article/17/11/how-use-cron-linux

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM