我想做一个python3脚本,在网页上寻找像“ArduinoON”之类的词。但进展并不顺利。我知道如何使用php,但不知道如何使用python。下面是我如何用php做的,以及我如何用python做的。你知道吗
下面是我如何用php实现的。你知道吗
<?php
$data = file_get_contents('http://192.168.0.200:9090');
$regex = '/Switch1On/';
if (preg_match($regex, $data)) {
echo '<font color="green">on</font>';
} else {
echo '<font color="red">off</font>';
}
?>
我的python代码
import urllib.request
x = urllib.request.urlopen('http://192.168.0.200:9090/')
if "ArduinoOn" in x:
print ("True")
有人能帮我吗?你知道吗
如果要在html页面中查找文本字符串,可以使用Pythonrequests模块。这可能是最简单的方法。你知道吗
在docs之后,
urllib.request.urlopen
返回一个http.client.HTTPResponse
对象。因此,如果您想获取页面内容,您应该阅读:希望这有帮助。你知道吗
相关问题 更多 >
编程相关推荐