Skip to content

Commit

Permalink
Fix ascendants import
Browse files Browse the repository at this point in the history
  • Loading branch information
romjerome authored Jun 11, 2021
1 parent a151439 commit 5518acf
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions GeneanetForGramps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,10 @@ def random_headers():
LOG.debug(_("Unable to perform HTML analysis via requests"))
# os.system('''wget "%(url)s"''' % {'url': purl})
import urllib.request
page = urllib.request.urlopen(purl)
try:
page = urllib.request.urlopen(purl)
except urllib.error.HTTPError:
LOG.debug(purl)
tree = html.fromstring(page.read())
LOG.info(str(page))

Expand Down Expand Up @@ -1389,30 +1392,33 @@ def random_headers():
LOG.info(etree.tostring(p, method='xml', pretty_print=True))
if verbosity >= 3:
print('parent text', p.xpath('text()'))
if p.xpath('text()')[0] == '\n':
for a in p.xpath('a'):
sosa = a.find('img')
if sosa is None:
try:
pname = a.xpath('text()')[0].title()
LOG.info(pnane)
except:
pname = str(uuid.uuid3(uuid.NAMESPACE_URL, 'parents'))
LOG.debug(pname)
LOG.info(p.text)
for a in p.xpath('a'):
pref = a.xpath('attribute::href')[0]
LOG.debug(pref[0])
#if p.xpath('a'):
#for a in p.xpath('a')[0]:
#sosa = a.find('img')
#if sosa is None:
#try:
#pname = a.xpath('text()')[0].title()
#LOG.info(pnane)
#except:
#pname = str(uuid.uuid3(uuid.NAMESPACE_URL, 'parents'))
#LOG.debug(pname)
# if pname is ? ? then go to next one
try:
pref = a.xpath('attribute::href')[0]
LOG.info(pref)
except:
LOG.debug(etree.tostring(a, method='xml', pretty_print=True))
pref = ""

if verbosity >= 1:
print(_("Parent name: %s (%s)") %(pname, ROOTURL+pref))
#try:
#pref = a.xpath('attribute::href')[0]
#LOG.info(pref)
#except:
#LOG.debug(etree.tostring(a, method='xml', pretty_print=True))
#pref = ""
#if verbosity >= 1:
#print(_("Parent name: %s (%s)") %(pname, ROOTURL+pref))
#else:
#LOG.info(etree.tostring(p, method='html', pretty_print=False))
#LOG.debug('Failed to set parents %s' % p.text)
prefl.append(ROOTURL+str(pref))
else:
LOG.info(etree.tostring(p, method='html', pretty_print=False))
LOG.debug('Failed to set parents')
try:
self.fref = prefl[0]
except:
Expand Down

0 comments on commit 5518acf

Please sign in to comment.