我有以下代码:
from bs4 import BeautifulSoup
import requests
import re
import time
import schedule
def scrape():
regex = r"\{.availability\":\"(?P<found>\w*\")"
URL = 'someurl'
headers = {
"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0'}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
scripts = str(soup.find_all('script'))
matches = re.finditer(regex, scripts, re.MULTILINE | re.DOTALL)
for matchNum, match in enumerate(matches, start=0):
print("{matchNum}: {match}".format(
matchNum=matchNum, start=match.start(), end=match.end(), match=match.group()))
schedule.every(3).seconds.do(scrape)
while 1:
schedule.run_pending()
time.sleep(1)
代码检查一篇文章是“缺货”还是“库存”。问题是,我必须像24/7一样在控制台等待“库存”出现。我在想,如何写几行代码来弹出一个通知,上面写着:“嘿,'库存'刚刚弹出!“或者我不知道,可能是一个简单的声音?(这可能更好)任何形式的通知。我真的非常感谢任何形式的帮助。我是Python的新手,所以如果我不知道基本的东西,我很抱歉。祝你有一个美好的夜晚
~EDIT-我用了这个:Play audio with Python
首先,使用pip安装win10toast:
然后,导入它:
创建一个名为toast的变量:
敬酒:
相关问题 更多 >
编程相关推荐