Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用beautifulsoup检查字符串是否存在_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

Python 如何使用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

您好,我正在尝试编写一个程序,删除一个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'):
    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。请你解释一下为什么你的答案中没有用到它。