如何通过管道将“ ngrok http 8000”的结果传输到另一个文件?

问题描述

我使用ngrok测试网络钩子,发现自己不断将新生成的ngrok主机复制/粘贴到多个位置,因此我决定使该过程自动化,但似乎找不到一种干净的方法来从ngrok进程中提取网址。

我希望能够将输出通过管道传输到文件,然后使用正则表达式或其他内容将其提取,但是 stdout 似乎为空。

例如,以下命令导致一个空文件:ngrok http 8000 > test.txt

这是 ngrok http 8000 的输出:

output of ngrok http 8000

我设法使用python + selenium和ngrok的“检查”找到了 hack

#!/usr/bin/env python3
from selenium import webdriver

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.firefox.options import Options
from selenium.common.exceptions import WebDriverException

def main():
    opts = Options()
    opts.headless = True
    bot = webdriver.Firefox(options=opts)
    bot.get('http://localhost:4040/inspect/http')
    url_xpath = '/html/body/div[2]/div/div/div/div/ul/li[1]/a'
    WebDriverWait(bot,10).until(EC.element_to_be_clickable((By.XPATH,url_xpath)))
    url = bot.find_element_by_xpath(url_xpath).text
    print(url.partition('://')[2])
    bot.close()


if __name__ == '__main__':
    main()

但是这很慢,并且为如此琐碎的事情编写了大量代码。而且,它也不是ngrok随机更改检查端口的原因。

有更好的方法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...