我现在有点迷茫,希望能帮到你!
我尝试在 Python 中识别使用 OpenCV 的人。到目前为止,这是有效的。使用识别出的人的 id,我想显示属于她或他的信息。
为此,我尝试了这样的事情:
1)
import webbrowser
webbrowser.open('http://mysite/index.php?userID=XYZ', new = 0)
但是,尽管我写了“new = 0”,但每次其他用户 ID 站在链接中时,它都会打开一个新的浏览器选项卡。
2)另一种方法是通过http post请求向网站发送信息,例如:
url = 'http://mysite/index.php'
query = {'personID': XYZ}
res = requests.post(url, data=query)
但是这样做我不知道如何在我的 PHP 代码中使用此 post 命令,因此它使用属于用户 XYZ 的数据刷新站点。
你能帮我吗?
亲切的问候
Edit1 - 开始:一个使用 GET 参数的小 php 示例将是这样的
<?php
echo("<html><head><title></title></head><body>");
if ($_GET['userID'] == 1) {
echo("<div id='userContent'>Hello User 1</div>");
}
else if ($_GET['userID'] == 2) {
echo("<div id='userContent'>Hello User 2</div>");
}
else {
echo("<div id='userContent'>Public, non user specific information</div>");
}
echo("</body></html>");
?>
但此时我不知道如何使这个站点成为一个动态站点,当 Python 发送请求时显示不同的信息。
编辑 1 - 结束
目前这在 webdriver 中是不可能的。0 标志指的是窗口,而不是选项卡。在此处查看 reddit 上对此的讨论。另一个问题也在 Stack Overflow 上问过这个问题,但没有得到答案。
然而,使用功能更丰富的软件包 Selenium 是可能的。
import time
from selenium import webdriver
link1="http://mysite/index.php?userID=ABC"
link2="http://mysite/index.php?userID=XYZ"
driver=webdriver.Firefox()
driver.get(link1)
time.sleep(5)
driver.get(link2)
Selenium 确实需要一些安装步骤:http : //selenium-python.readthedocs.io/installation.html
关于使用 requests,您没有理由不能执行GET请求,因此您不必担心处理 post 请求:
import requests
url = "http://mysite/index.php?userID=ABC"
res = requests.get(url)
print(res.text)
没有看到更多的 php 代码或了解更多的细节,很难说哪种方法最适合你,但这应该能让你克服你提到的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句