繁体   English   中英

如何连接到页面并检查页面中是否存在单词

[英]how to connect to page and check a word exist in page

我想每 5 秒通过urllib2连接到一个站点并在此之后获取所有 html 我想检查一个单词是否在页面中

例如,我想每 5 秒连接到google并检查 google 是否在页面中

我试试这个代码:

import urllib2
import time

while true:
    values = urllib2("http://google.com")
    if "google" in values:
        print("google is in my address")
    else:
        print("google not in my address")
    time.sleep(5)

我使用 python 2.7

你的代码有错误

将您的代码更改为:

import urllib2
import time

while true:
    values = urllib2.urlopen("http://google.com").read()
    if "google" in values:
        print("google is in my address")
    else:
        print("google not in my address")
    time.sleep(5)

此代码每 5 秒检查一次您的网站

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM