您好,我正在尝试编写一个程序来抓取 URL,如果抓取数据包含特定字符串,我该如何使用漂亮的汤来实现此目标
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")
