Python 使用函数的结果作为搜索条件
我想将函数Python 使用函数的结果作为搜索条件,python,function,Python,Function,我想将函数defecillic()的第一个结果插入第二个函数entity\u noon()。在第二个函数中,它查找具有特定值的属性的节点。我希望从第一个函数的返回值中检索此值(它是引号中的字符串) from bs4 import BeautifulSoup def elliptic(): last_a_tag = soup.find_all("sn", elliptic="yes") for item in last_a_tag: entity = it
defecillic()
的第一个结果插入第二个函数entity\u noon()
。在第二个函数中,它查找具有特定值的属性的节点。我希望从第一个函数的返回值中检索此值(它是引号中的字符串)
from bs4 import BeautifulSoup
def elliptic():
last_a_tag = soup.find_all("sn", elliptic="yes")
for item in last_a_tag:
entity = item.get('entity')
return(entity)
def entity_noun():
ent = soup.find(entity="??????")
noun = ent.find('n')
return(noun)
你有什么建议怎么做 这里有两个函数。应调用函数以返回结果。 如果您这样做:
from bs4 import BeautifulSoup
def elliptic():
last_a_tag = soup.find_all("sn", elliptic="yes")
for item in last_a_tag:
entity = item.get('entity')
return(entity)
def entity_noun():
ent = soup.find(entity=elliptic())
noun = ent.find('n')
return(noun)
entity_noun()
您将调用entity\u noun()
,它将调用椭圆()
另一个选项是使用参数:
from bs4 import BeautifulSoup
def elliptic():
last_a_tag = soup.find_all("sn", elliptic="yes")
for item in last_a_tag:
entity = item.get('entity')
return(entity)
def entity_noun(X):
ent = soup.find(entity=X)
noun = ent.find('n')
return(noun)
A=elliptic()
entity_noun(A)
在这种情况下,您将调用第一个函数椭圆()
将结果保存在A
中,然后将A
传递给实体名称()
。使用第二种方法,每个函数将彼此独立,因此可以在不同的上下文中独立使用 您可以在参数中传递调用函数的结果
因此,在这种情况下,您将执行以下操作:
ent = soup.find(entity=elliptic())
ent=soup.find(entity=椭圆()