ISSUE RESOLVED.

I fixed the error by checking for attrsLen property like this:
    
    
    import htmlparser
    import xmltree
    import strtabs
    import strutils
    
    
    let allhtml:File = open("allhtml.txt")
    var line: string
    var count = 0
    while allhtml.readline(line):
      echo "HTML file: ", count, line
      let html = loadHTML(line.strip())
      for a in html.findall("a"):
        if a.attrsLen > 0:
          let url = a.attrs.getOrDefault("href")
          if not url.isNil:
            if url.startswith("/"):
              echo "$1\t$2" % [line, url]
      count += 1
    
    close(allhtml)
    

Reply via email to