[使用机械化python搜索URL中的文本

问题描述 投票:1回答:1

您好,我需要检查url页面中是否包含诸如'good'之类的文本。我正在使用机械化功能,在此网站上看到了一些响应,但在其他站点上却没有人响应。我看到了'''.body.include?()'''但这对我不起作用,请帮助我我知道网站上的支票还可以的时候说Godd new,所以我尝试了此

if "Good news" in isitwp_response:
    rowdict['iswordpresswebsite'] = "yes"
else:
    rowdict['iswordpresswebsite'] = "no

但是那对我不起作用。

python regex mechanize
1个回答
0
投票

您需要解析信息。尝试使用bs4类的BeautifulSoup。首先,响应本身不会告诉您任何信息。尝试使用isitwp_response.read()获取该站点的实际信息。

喂汤

soup = bs4.BeautifulSoup(isitwp_response.read(),'html.parser')

find()函数将返回您正在搜索的文本(如果存在)。 (在其他站点上经过测试)

if soup.find(text='Good news')==None:
    return(False)
else:
    return(True)
© www.soinside.com 2019 - 2024. All rights reserved.