lxml

Can not use translate() method in xpath with lxml etree

Can not use translate() method in xpath with lxml etree Question: I want to use translate to lower my text with lxml library in Python. My code is as below r = element.xpath(‘./a/translate(text(), "A", "a")’) But it give me an exception: lxml.etree.XPathEvalError: Invalid expression I’d like to do this with xpath only (without writing code …

Total answers: 1

XML and probably LXML issue

XML and probably LXML issue Question: I have many XML files that look like this <?xml version="1.0" encoding="utf-8" standalone="no"?> <reiXmlPrenos> <Qfl>1808</Qfl> <fOVE>13.7</fOVE> <NetoVolumen>613</NetoVolumen> <Hv>104.2</Hv> <energenti> <energent> <sifra>energy_e</sifra> <naziv>EE [kWh]</naziv> <vrednost>238981</vrednost> </energent> <energent> <sifra>energy_to</sifra> <naziv>Do</naziv> <vrednost>16359</vrednost> </energent> <energent> <sifra>energy_en</sifra> <naziv>En</naziv> <vrednost>0</vrednost> </energent> </energenti> <rei> <zavetrovanost>2</zavetrovanost> <cone> <cona> <cona_id>1</cona_id> <cc_si_cona>1110000</cc_si_cona> <visina_cone>2.7</visina_cone> <dolzina_cone>14</dolzina_cone> </cona> <cona> <cona_id>2</cona_id> <cc_si_cona>120000</cc_si_cona> </cona> …

Total answers: 2

python lxml.etree generating empty tree when given requests.get().text

python lxml.etree generating empty tree when given requests.get().text Question: I am trying to build a web scraper for TEDTalks and am running into an issue when generating transcripts. Python 3.10.4, lxml 4.9.2. First I am generating the html response like this. text = requests.get(‘https://www.ted.com/talks/ted_countdown_how_do_we_get_the_world_off_fossil_fuels_quickly_and_fairly/transcript’, headers={}).text when checking the value of text, it shows me that …

Total answers: 1

getpath in lxml etree is showing different output for absolute xpath

getpath in lxml etree is showing different output for absolute xpath Question: I am trying to get the absolute XPath of an element but it is giving different output. I am trying to get the full XPath of search button in Google. Here’s the code I have tried: import time import random from selenium import …

Total answers: 1

"CData section too big" error when parsing XML with lxml

"CData section too big" error when parsing XML with lxml Question: I’m trying to parse a XML file using etree, parsing the file with tree = etree.parse(path_to_xml) is giving me an error : lxml.etree.XMLSyntaxError : CData section too big So I’ve tried to remove all the CData tags but in order to read it I …

Total answers: 1

lxml fails to import, with error `symbol not found in flat namespace '_xsltDocDefaultLoader'`

lxml fails to import, with error `symbol not found in flat namespace '_xsltDocDefaultLoader'` Question: With the code: from lxml.etree import HTML, XML I get the traceback: Traceback (most recent call last): File "/Users/username/code/project/lxml-test.py", line 3, in <module> from lxml.etree import HTML, XML ImportError: dlopen(/Users/username/.virtualenvs/project-venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace ‘_xsltDocDefaultLoader’ I’m on a …

Total answers: 2

lxml .text returns None when string contains tags

lxml .text returns None when string contains tags Question: I am a traversing complex XML file with millions of TU nodes and extracting strings from <seg> elements. Whenever <seg> element contains serialized tags, I get None object instead of a string. Code that returns None: source_segment = ET.parse(file).getroot().find(‘body’).findall(‘tu’)[0].findall(‘tuv’)[0].find(‘seg’).text Sample content of <seg> element that causes …

Total answers: 2

How to rewrite thid XML file?

How to rewrite thid XML file? Question: I trying to rewrite this xml file containing this XML code: <?xml version="1.0" encoding="UTF-8"?> <BrowserAutomationStudioProject> <ModelList> <Model> <Name>token</Name> <Description ru="token" en="token"/> <Value>5660191076:AAEY8RI3hXcI3dEvjWAj7p2e7DdxOMNjPfk8</Value> </Model> <Defaults/> <Model> <Name>chat_id</Name> <Value>5578940124</Value> </Model> <Defaults/> </ModelList> </BrowserAutomationStudioProject> My python code: import xml.etree.ElementTree as ET tree = ET.parse(‘Actual.xml’) root = tree.getroot() for model in root.findall(‘Model’): …

Total answers: 3