I want to parse mail from the site, but the script for some reason gives an empty list ! [enter image description here

code

all_links = [] def get_links(): try: page = requests.get(url) tree = html.fromstring(page.content) links = tree.xpath('//h2[@itemprop="name"]/a') for lnk in links: all_links.append('https://www.ua-region.info{}'.format(lnk.get('href'))) print('https://www.ua-region.info{}'.format(lnk.get('href'))) except Exception as e: print(e) for url in all_pages: get_links() print('{} links found'.format(len(all_links))) mails = [] **def get_mail(): try: mail = [i.text.encode('utf-8') for i in tree.xpath('//td[@itemprop="email"]/a')] print(mail) except Exception as e: print(e) print('mail not found') mails.append('')** 

code on page enter image description here

What needs to be fixed?

full code https://pastebin.com/Tkg8egtP

  • one
    no need to put all code indiscriminately in the question, try to create a minimal example that shows the minimum reproducible error - jfs
  • @jfs so how do you make a reproducible python example? - ishidex2
  • And you have mails only in cases of error is filled - gil9red
  • one
    @ Elena, and now you have a too short example: there is a call to the get_links() function, but there is no function itself. The problem is in her. And the link to pastebin does not have this function either. - insolor
  • pastebin.com/Tkg8egtP here is the complete code and the question wrote the function get_links () - Elena

0