如何使用python-2.7检查字典键值是否存在于另一个函数中

时间:2015-12-31 05:42:37

标签: python-2.7 dictionary beautifulsoup

我正在使用python-2.7并从另一个函数中检索字典的键值。

我的代码 -

function1(self):
self.dict1 = {'Old_link':id} # dict1 contains many such key-value wherein key=link,value=id
....#some
....#code

function2(self):
....#some
....#code
soup = BeautifulSoup(page, "lxml")  #creates a soup
self.tag1 = soup.findAll("div","class_name")
for i in self.tag1:
    self.Old_link = i.find('a').get('href')
try: 
    #insert into table query
    self.id = cursor.lastrowid
    self.dict1['Old_link'] = self.id
except: 
        print(error)


function3(self):
  soup = BeautifulSoup(page, "lxml")  #creates a soup
  self.tag = soup.findAll("div","class_name")
  for i in self.tag:
    self.New_link = i.find('a').get('href')
                if self.New_link == any self.dict1.has_key(self.Old_link):
                # get the id and match with other_id

如何将New_link与来自function1()的旧链接匹配

我为没有正确询问而道歉。

欢迎以任何形式提供帮助/指导。

提前致谢。

0 个答案:

没有答案