您好,我正在尝试编写一个程序来抓取 URL,如果抓取数据包含特定字符串,请执行某些操作,我如何使用 beautiful soup 来实现此目的
import requests
from bs4 import BeautifulSoup
data = requests.get('https://www.google.com',verify=False)
soup= BeautifulSoup(data.string,'html.parser')
for inp in soup.find_all('input'):
if inp == "Google Search":
print ("found")
else:
print ("nothing")
你的 inp 是一个 html 对象。您必须使用 get_text() 函数
import requests
from bs4 import BeautifulSoup
data = requests.get('https://www.google.com',verify=False)
soup= BeautifulSoup(data.string,'html.parser')
for inp in soup.find_all('input'):
if inp.get_text() == "Google Search":
print ("found")
else:
print ("nothing")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)