javascript - Python HTML getElementsByClassName alike manipulate on file content -


i have saved source code of page file using sikuli. need "roundup" on batch of matrix style placed elements. don't want calculate dimensions between them. want urls type in location bar. wrote scratch of mzdn javascript implementation of such "simple" operation. don't want use lxml. want real native libraries - mean need "portable" script. i've googled while , decided ask question @ stack overflow. don't want use

split('<a href=') 

magic. in python(in pythonic way):

var array = document.getelementsbyclassname('another')  var j = array.length (i=0;i<j;i++) {     element = array[i];     url = element.getelementsbytagname('a')[0].href;     console.log(url);     }  var array = document.getelementsbyclassname('else') var j = array.length (i=0;i<j;i++) {     element = array[i];     url = element.getelementsbytagname('a')[0].href;     console.log(url);     } 

managed split. python kids.

def read_file(filename):     fd = open(filename, 'r')     data = fd.read()     fd.close()     return data  def href(line):         url = line.split('a href=')[1].split('>')[0].strip().replace('"', '').replace("'", '')         return url  html = read_file('source.htm').split('\n') line in html:     if 'one' in line:         print href(line)     elif 'another' in line:         print href(line)     elif 'else' in line:         print href(line) 


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -