lxml

How to print line number for specific condition in xml using python

How to print line number for specific condition in xml using python Question: My xml is <File> <Sub_Function_1> <Messages> <Setting> <Data> <Label>Setting_1</Label> <Value> <Measure> <Data>Area</Data> <Bound> <Value> <Data>2000</Data> </Value> <Condition> <Data>0</Data> </Condition> </Bound> <Bound> <Value> <Integer>10000</Integer> </Value> <Condition> <Integer>12000</Integer> </Condition> </Bound> </Measure> </Value> </Data> <Data> <Label>Setting_2</Label> <Value> <Measure> <Data>Area_2</Data> <Bound> <Value> <Integer>2000</Integer> </Value> <Condition> <Data>0</Data> …

Total answers: 1

How to print line number specific element inside complex child elements using python

How to print line number specific element inside complex child elements using python Question: Example of my XML1 consists of format of Equal element : <Operator> <Equal> <Data>A1</Data> <Data>2</Data> </Equal> <Equal> <Integer>A2</Integer> <Data>2</Data> </Equal> <Equal> <Integer>A3</Integer> <Integer>2</Integer> </Equal> </Operator> And the following code runs fine for finding ‘equal’ elements if there are not many child …

Total answers: 1

How to print line number of element if it equals specific format given in one XML searched in another XML

How to print line number of element if it equals specific format given in one XML searched in another XML Question: Example of my XML1 consists of format of Equal element : <Operator> <Equal> <Data>OPERATING_MODE</Data> <Data>2</Data> </Equal> <Equal> <Integer>Remote_Request</Integer> <Data>2</Data> </Equal> <Equal> <Integer>Real_area</Integer> <Integer>2</Integer> </Equal> </Operator> And the following code runs fine for finding elements …

Total answers: 1

How to add comments in XML using python

How to add comments in XML using python Question: XML i am parsing: <List> <Item> <Price> <Amount>100</Amount> <Next_Item> <Name>Apple</Name> </Next_Item> <Next_Item> <Name>Orange</Name> </Next_Item> </Price> <Price> <Amount>200</Amount> <Next_Item> <Name>Apple</Name> </Next_Item> <Next_Item> <Name>Orange</Name> </Next_Item> </Price> </Item> </List> In Output XML i want to add a comment above Next_Item: <List> <Item> <Price> <Amount>100</Amount> <!–Not-Needed–> <Next_Item> <Name>Apple</Name> </Next_Item> <Next_Item> …

Total answers: 2

I want to remove the unwanted sub-level duplicate tags using lxml etree

I want to remove the unwanted sub-level duplicate tags using lxml etree Question: This is the input sample text. I want to do in object based cleanup to avoid hierarchy issues <p><b><b><i><b><i><b> <i>sample text</i> </b></i></b></i></b></b></p> Required Output <p><b><i>sample text</i></b></p> Asked By: Rajeshkanna Purushothaman || Source Answers: Markdown, itself, provides structural to extract elements inside Using …

Total answers: 3

How to get weather data from site?

How to get weather data from site? Question: I’m not able to get the Dew_Point and Wind Data from the site https://weather.gc.ca/city/pages/ab-52_metric_e.html import requests from lxml import html # Get the html page resp=requests.get("https://weather.gc.ca/city/pages/ab-52_metric_e.html") # Build html tree html_tree=html.fromstring(resp.text) #Dew_point=html_tree.xpath("//dd[@class=’mrgn-bttm-0 wxo-metric-hide’][(parent::dl[@class=’dl-horizontal wxo-conds-col2′])]//text()")[1].replace("Â", "") # Print Dew_point #print(f"Dew_point in {city_name} is {Dew_point}") #Wind=html_tree.xpath("//dd[@class=’longContent mrgn-bttm-0 wxo-metric-hide’][(parent::dl[@class=’dl-horizontal wxo-conds-col2′])]//text()")[0].replace("Â", …

Total answers: 2

xpath selector in bs4 and xml doesn't work

xpath selector in bs4 and xml doesn't work Question: i want to get the rank data from this link https://zapper.fi/nft/ethereum/0x2a6eec51ee67a941fa50c1fbc4ca8853604461b8/616 but the returned result for me is [] my code is as follow : import requests from bs4 import BeautifulSoup from lxml import etree url = ‘https://zapper.fi/nft/ethereum/0x2a6eec51ee67a941fa50c1fbc4ca8853604461b8/616’ webpage = requests.get(url, headers=HEADERS) soup = BeautifulSoup(webpage.content, "html.parser") …

Total answers: 1

LXML/Requests-HTML: Get element after plain text, both children of same element?

LXML/Requests-HTML: Get element after plain text, both children of same element? Question: I’m new to web scraping, and I’m currently using requests, requests-html, and lxml. I’m having trouble figuring out how to target the "DESIRED INFO" from the specific <span> element in the following circumstance (a lot of info is thrown into a single <td>): …

Total answers: 2

python lxml save question with special character in string

python lxml save question with special character in string Question: Updated my question, did not realize it had formatted my text When I save my xml using lxml it converts &amp; to &amp;amp; When I debug and pull that value after adding it, it’s correct, but when it saves it adds the extra amp; to …

Total answers: 2

Working with picture in AlternateContent tag

Working with picture in AlternateContent tag Question: I need to move an element from one document to another by using python-docx. The element is AlternateContent which represents shapes and figures in Office Word, the issue here is that one of the elements contains an image like this: <AlternateContent> <Choice Requires="wpc"> <drawing> <inline distT="0" distB="0" distL="0" …

Total answers: 1