From the xml file:

<items> <item id="26479957"> <genre>статья в журнале</genre> <type>научная статья</type> <source> <journal> <title>Современные научные исследования и инновации</title> <eissn>2223-4888</eissn> <publisher>Общество с ограниченной ответственностью Международный научно-инновационный центр</publisher> <country>RUS</country> <town>Москва</town> <vak>no</vak> <rsci>no</rsci> <wos>no</wos> <scopus>no</scopus> </journal> </item> <item id="21373499"> <genre>статья в журнале</genre> <type>научная статья</type> <source> <journal> <title>Исторические, философские, политические и юридические науки, культурология и искусствоведение. Вопросы теории и практики</title> <issn>1997-292X</issn> <publisher>Общество с ограниченной ответственностью Издательство Грамота</publisher> <country>RUS</country> <town>Тамбов</town> <vak>no</vak> <rsci>no</rsci> <wos>no</wos> <scopus>no</scopus> </journal> </item> </items> 

I try to pull out eissn, if it is not in the current tag, then I pull issn:

 def get_issn_eissn(item) -> str: for issn in item: if issn in item: publ_issn = item.find_all("issn")[0] return publ_issn.text else: publ_eissn_issn = item.find_all("eissn")[0] return publ_eissn_issn.text 

Error: list index out of range. Tell me, please, how can I correct this error? Thanks in advance for your reply.

  • I found this not very convenient option: def get_issn (item) -> str: for issn in item: if issn in item: publ_issn = item.find ("issn") return publ_issn else: break - Ireen1985
  • Your broken XML - tag <source> not closed. eissn your task to find eissn / issn in one element or to find them all in the whole document? - MaxU
  • one
    It's simple: if item.find_all(...) returns an empty list, then item.find_all(...)[0] causes that error, check that the list is not empty, before calling [0] , or use the search, which returns 1 element - find - gil9red
  • Throughout the document. tag <source> is not closed, because I manually inattentively cut the file - Ireen1985
  • Made through find. It worked. Thank! - Ireen1985

0