Answer the question
In order to leave comments, you need to log in
Python. How to get the value of the tag parameter when parsing?
Hello. When parsing the page, you need to get the value "B01CZ654Q6" from the data-asin parameter
<li id="result_1418" data-asin="B01CZ654Q6" class="s-result-item s-result-card-for-container s-carded-grid celwidget ">
Answer the question
In order to leave comments, you need to log in
>>> from lxml import etree
>>> str1 = '<li id="result_1418" data-asin="B01CZ654Q6" class="s-result-item s-result-card-for-container s-carded-grid celwidget "></li>'
>>> elem = etree.fromstring(str1)
>>> elem.get('data-asin')
'B01CZ654Q6
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question