问题描述
我使用ngrok测试网络钩子,发现自己不断将新生成的ngrok主机复制/粘贴到多个位置,因此我决定使该过程自动化,但似乎找不到一种干净的方法来从ngrok进程中提取网址。
我希望能够将输出通过管道传输到文件,然后使用正则表达式或其他内容将其提取,但是 stdout
似乎为空。
例如,以下命令导致一个空文件:ngrok http 8000 > test.txt
这是 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 (将#修改为@)