Python 如何使用beautifulsoup检查字符串是否存在
您好,我正在尝试编写一个程序,删除一个URL,如果删除的数据包含一个特定的字符串,我该如何使用BeautifulSoup来实现这一点Python 如何使用beautifulsoup检查字符串是否存在,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,您好,我正在尝试编写一个程序,删除一个URL,如果删除的数据包含一个特定的字符串,我该如何使用BeautifulSoup来实现这一点 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
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")
验证=False,禁用证书验证。这是一个安全问题。特别是如果你在公司的网络里面,这是危险的,因为它打开了中间人攻击的可能性。您应该使用适当的证书授权。如果inp中的“谷歌搜索”可能是
:
?欢迎使用SO@MLAlex。请你解释一下为什么你的答案中没有用到它。