lxml - printing title of URL from a file in python -


I am trying to fetch the URL from the file and output the title of the page:

 < Code> Import to line in file lxml.html file = open ('ab.txt', 'r'): t = lxml.html. Identical (line) print t.find (".// headline"). Text   

error:

  traceback (most recent call final): File "C: \ Python 27 \ site.py", line 4, & Lt; Module & gt; T = lxml.html .parse (line) file "C: \ Python27 \ lib \ site-package \ lxml \ html \ init__.py __", line 661, parse return in etree.parse (filename_or_url, parser, base_url = base_url , ** kw) file "lxml.etree.pyx", in line 2706, lxml.etree.parse (src / lxml / lxml.etree.c: 49958) in the file "parser.pxi", line 1500, lxml.etree . _parseDocument (src / lxml / lxml.etree.c: 71,797) The file "parser.pxi", line 1529, in lxml.etree._parseDocumentFromURL (src / lxml / lxml.etree.c: 72,080) file "parser.pxi" In the line 1429, lxml.etree._parseDocFromFile (src / lxml / lxml.etree.c: 71,175) the file "parser.pxi", line 975, lxml.etree._BaseParser._parseDocFromFile (src / lxml / lxml.etree.c : 68,173) file "parser.pxi", line 539, in lxml.etree._ParserContext._handleParseResultDoc (src / lxml / lxml.etree.c: 64,257) file "parser.pxi", line 625, in lxml.etree._handleParseResult (Src / lxml / lxml.etree.c: 65,178) IOError in the file "parser.pxi", line 563, lxml.etree._raiseParseError (src / lxml / lxml.etree.c: 64,493): Error reading file 'http : //example.com/5129860 ': Failed ODP HTTP in L  

Is there anything wrong here?

parse method lxml.html a file Returns the object in an HTML document like a name, a URL, or a file and gives a tree, with documentation, the arguments for this function are in this way,

  parse (file name_array, pars = None, base_url = none, ** kw)   

Then you can pass the file name directly and get your output.

  t = lxml.html.parse ('ab.txt') print t.find (".// title").    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -