Questions tagged [lxml]
lxml is a full-featured, high performance Python library for processing XML and HTML.
5,173
questions
0
votes
0
answers
10
views
Loop through XML to change value
I would like to loop through an XML and modify the value of start/finish according to a dataframe (Excel file imported as dataframe, maybe there is a better way to do it?). This is a script I'll have ...
0
votes
0
answers
25
views
'ImportError: lxml not found, please install it'
I am new to coding and SO so apologies for any SO formatting mistakes. I am currently getting the following error, 'ImportError: lxml not found, please install it', even though I have already ...
0
votes
1
answer
31
views
Python3 - How can I fetch all elements from div (XPath)?
import requests
from lxml import html
response = requests.get("https://stackoverflow.com/")
content = html.fromstring(response.text)
a = content.xpath('/html/body/div[4]/div[2]/div[1]/div[1]...
-2
votes
0
answers
45
views
SyntaxError: unterminated string literal in python [closed]
i have got a problem i am trying to build a script here but am getting this error over and over, it is taking the subject line fine but it is showing error in the content line , if i add paragraph ...
0
votes
1
answer
26
views
How do I use LXML to return href attribute in path as string?
I have working code that prints element
'//*[@id=all_TorontoBlueJayspitching"]/div/table/tbody/tr/th/a/text()'
From the site https://www.baseball-reference.com/boxes/CHA/CHA202206200.shtml
Using ...
0
votes
0
answers
43
views
How can I insert an Entity element using lxml?
I'd like to insert into an ElementTree an entities element of the form <!ENTITY % entities SYSTEM "entities.ent"> where the string entities.ent is variable.
0
votes
1
answer
43
views
Unable To find the correct xpath for a website in python
I am trying to get the data from https://www.reuters.com/markets/companies/AALI.JK/key-metrics/per-share-data
for data of the EPS Normalized (Annual) 1,010.14 in xpath.
Kindly click for the inspect ...
0
votes
2
answers
40
views
How to retain custom entities like – while transforming the xml using xslt
I'm trying to transforming xml using xslt, here is the example I'm using....
Input xml:
<!DOCTYPE printArtifactGroup [<!ENTITY ndash "&#38;ndash;">]>
<group>
<...
-1
votes
0
answers
86
views
How do I resolve XML symbols in external namespace in python
I'm trying to parse and resolve a bunch of DC metadata for an epub file and I want to resolve (not sure if that's even the proper terminology) some symbols, but I have no idea how that works in XML.
...
2
votes
2
answers
45
views
LXML the .xpath() method context node is not properly recognized in predicates?
I have a problem with Packet LXML (lxml 4.8.0) for Python.
I am using the method .xpath() and it is not behaving as I thought it would.
The following XML file has an element CONTEXT.
I find this with ...
0
votes
0
answers
54
views
Using lxml and etree to get nested elements
I'm using LibXML etree to parse one XML file and write elements of it to a new file. For the most part I've been able to get single elements by specifying points in the tree but I've come across a ...
-2
votes
1
answer
55
views
Python + XML documents
I'm a bit new to XML and python. Below is a cut down version of a large XML file I'm trying to bring into python to eventually write into SQL Server db.
<?xml version="1.0" encoding="...
0
votes
0
answers
20
views
Trouble parsing CNN search results using Python 3 lxml
I am trying to parse the response from a search on the CNN site like so:
import requests
from lxml import html
from lxml import etree
r = requests.get('https://www.cnn.com/search?q=climate+change')
...
0
votes
0
answers
28
views
Encoding problem when reading urls from a csv file in python [duplicate]
I have a csv file with some urls; after reading through it, in python with:
import csv
rows = []
with open("links.csv","r", encoding = "utf-8") as c:
csv_reader = csv....
1
vote
1
answer
41
views
Python lxml requests: Only last xpath search is working
Ive reciently tried building a short cardmarket(a website to see cardgame card prices) checker,
which takes the prices via the xpath from the website. Now I thought everything worked fine until I ...
1
vote
1
answer
34
views
How to create an objectified element with text with lxml
I'd like to create an element tree (not parsing!) with lxml.objectify that might look like this:
<root>
<child>Hello World</child>
</root>
My first attempt was to write code ...
0
votes
1
answer
48
views
Data Scraping of the Numbers and details from the website
I want to scrape the contact numbers from the website with the respective details of the Courier Services. I am not able to scrape the Contact numbers and other details like name address and rating ...
-1
votes
1
answer
55
views
How to grab all prices off of site webscraping
So this is what I have, & this though it looks kind of funny... will print the 1st 10 prices only from zillow.
How would you write this to grab all items off of the page? (Bonus if you pretty ...
-1
votes
1
answer
41
views
lxml to grab All items that share a certain xpath
I'm trying to grab all prices from a website, using the xpath. all prices have the same xpath, and only [0], or I assume the 1st item works... let me show you:
webpage = requests.get(URL, headers=...
1
vote
1
answer
27
views
LXML - .//{DAV:}response raises lxml.etree.XPathEvalError: Invalid expression
I'm trying to get all response tags by using:
.//{DAV:}response
tree = etree.fromstring(r.content)
for response in tree.xpath(".//{DAV:}response"):
...
The problem is that lxml ...
1
vote
1
answer
38
views
Python 2.7 lxml: How to replace a tag with a comment
I have the fallowing XML:
<?xml version='1.0' encoding='UTF-8'?>
<A xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://obe.nce.amadeus....
0
votes
2
answers
40
views
Data Scraping for Pagination of the Products to get all products details
I want to scrape all the product data for the 'Cushion cover' category having URL = 'https://www.noon.com/uae-en/home-and-kitchen/home-decor/slipcovers/cushion-cover/'
I analysed the data is in the ...
0
votes
1
answer
60
views
Python lxml. Use findall with a variable
An XML snippet looks like this:
<certificate name='first_item'>First text,</certificate>
<certificate name='second_item'>Second text,</certificate>
<certificate ...
0
votes
1
answer
34
views
Python lxml not read XML properlly
I am using Python 2.7 (I can not upgrade to any new version sadly) and I am trying to parse 2 XML files, using lxml but something is not right and I am not sure what I am doing wrong:
CODE:
from lxml ...
0
votes
1
answer
54
views
XML parser incorrectly missing tags
I am parsing docs from the SEC EDGAR system.
When I use the lxml parser, it seems to parse correctly (although it lower-cases XML tags). When I use the xml parser, it seems to incorrectly understand ...
0
votes
1
answer
24
views
Beautiful Soup lower-casing tags by default?
I am using LXML with Beautiful Soup. I have an XML document that has upper-case tags. When I use BeautifulSoup, it seems to lower-case the tag names which makes my use of find_all un-intuitive. Does ...
0
votes
1
answer
41
views
Ho to fix xpath for lxml
Can somebody explain me why xptah on elementree works while it fails on element.
It's working
import lxml.etree as et
xml1 = et.parse(DATA1)
xml1.xpath("ws:Book[ws:Additional_Information/ws:...
0
votes
0
answers
27
views
Unable to edit an xml file
I have a xml file with b'+ xml_content +' in the file and
I want to delete the "b'" and "'" from starting and ending of the file so that I can parse the xml content but when I am ...
0
votes
0
answers
52
views
AWS Glue ImportError: cannot import name objectify from lxml
Environment: Glue 3.0, Python 3.7
Downloaded and added wheel file in Glue's Python library path of lxml-4.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl which I ...
0
votes
0
answers
23
views
Python SVG remove all tags with specific id attribute
I have an SVG image with Model and Group as ID attribute of tag g, like
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/...
0
votes
1
answer
27
views
How to validate XML with multiple XSD stored in Odoo modules
I need to validate an xml that I generate with two XSD files provided. I am struggling because one of the XSD files references the other one and it looks that I am getting errors because of that.
The ...
2
votes
1
answer
31
views
Make python requests and BeautifulSoup faster
Hi I want to get some data from a website (users and user's data) and them save data in a SQLite database.
I want to make this processes more faster
and witch is better comet data for every filed or ...
0
votes
0
answers
37
views
Remove "ds:" in signed XML tree namespace in python's signxml
I am working with Python's lxml and signxml to generate an xml file and sign it with a pem certificate and private key. I am also required to validate the signed xml file with an XSD file.
I will not ...
0
votes
0
answers
35
views
How to remove just script tags and its content by keeping all other tags intact in Python
I am trying to sanitize HTML content in python. I tried using lxml.html.clean as below
from lxml.html.clean import Cleaner
from lxml import html
cleaner = Cleaner(page_structure=False, safe_attrs=...
0
votes
0
answers
61
views
How can I remove all comments on a large xml file using python?
I am working on a small project for my office. The purpose of this script is take the inputs (siteid), and open/recall information from that file. Once the file has been opened/recalled, the script ...
-1
votes
3
answers
65
views
How to change the structure of a an XML in python
From this string :
label_config={
"label1": [
"modality1",
"modality2",
"modality3"],
"choice":"single",
...
0
votes
1
answer
45
views
Mypy Function "lxml.etree.ElementTree" is not valid as a type but why?
I am using Mypy for this function
import funcy as fu
from lxml import etree
from lxml.etree import Element, ElementTree
def find_nodes(tree: ElementTree, paths: Iterable[str]) -> Iterable[Element]:...
0
votes
0
answers
22
views
pandas read_htm parse fails for lxml
I definitely have lxml installed but pandas read_html thinks not. (I am on windows10 python38).
my code:
# problem: lxml not found, please install it
import pandas as pd
import lxml # IS ...
0
votes
1
answer
21
views
Is there any way to outout blank as in lxml or other python xml lib?
my code is:
>>> from lxml.html import tostring, HtmlElement
>>> a = HtmlElement()
>>> a.tag = "div"
>>> a.text = " "
>>> tostring(a)
b'&...
0
votes
0
answers
39
views
installed lxml using pipenv but BeautifulSoup cannot find it
I am trying to use the lxml parser. I installed it in my virtual env using pipenv install lxml.
I see it installed but continue to get the error:
FeatureNotFound: Couldn't find a tree builder with the ...
1
vote
0
answers
42
views
Add an element before text with lxml
I have some XML where I want to insert a new element before the text.
I tried:
from lxml import etree
xml = "<root><foo>some text</foo></root>"
root = etree....
0
votes
0
answers
24
views
Make a table out of a web page with Python (Requests)
I'm trying to make a table out of this web page (www.as.com). this is the output i'm trying to get
Any help is appreciated!
0
votes
1
answer
26
views
Parsing xml files without pretty print format
I am trying to parse XML that has been pretty printed, but without the pretty print formatting. It seems all parsing methods I have tried so far however include the formatting. For example,
xml = ...
0
votes
0
answers
32
views
Library that supports XPath 2.0 in Python
Is it possible to use XPath 2.0 functions like starts-with(), ends-with() and contains() in Python? I was trying to use lxml and defusedxml, but unfortunately they do not support any of these ...
-1
votes
1
answer
45
views
Access Popup Source code - Python requests
I'm trying to scrape some data from a website.
Adress: https://park4night.com/carte_lieux?lat=41.25807499996962&lng=9.426118999656891&zoom=38
I would like to get the link in the popup ...
0
votes
0
answers
32
views
How do I parse an XML file with lxml while keeping entity references?
This question is similar to Is there a way to make lxml preserve   like beautifulSoup?.
Here is my case:
File (just the part i'm interested in):
<child>&nbps;</child>
Code:
...
0
votes
0
answers
26
views
Wikipedia scrapping problem, how I can get content all tags inside one
I got a problem while trying to scrap wikipedia page. I want to get definition of title, but inside the tag I'm interested in there are many other tags, and I don't understand how I can obtain content ...
1
vote
1
answer
25
views
Adding a subelement iteratively with lxml
I want to add subelements iteratively e. g. from a list to a specific position of an XML path using XPath and a tag. Since in my original code I have many subnodes, I don't want to use other functions ...
0
votes
0
answers
42
views
lxml typing hints goes mad
i just can't understand why is so bad?
i'm doing nothing wrong, everything is working just fine
but Pylance having so much complaining about ~_~
root = lxml.html.fromstring(html.content) # type: ...
2
votes
1
answer
76
views
Parsing a XML child element back as a string
I'm trying to parse a complex XML and xpath isn't behaving like I thought it would.
Here's my sample xml:
<project>
<samples>
<sample>show my balance</sample>
...