python XML set SubElement with variable instead of string




-<Products Category="Watches">


-<pro_id id="[i]">

<product_name>Analog Watch</product_name>

<Link>Blah</Link>

<Image_link>Blah Again</Image_link>

<Original_price>2000</Original_price>

<Selling_price>1000</Selling_price>

<Discount>50%</Discount>

</pro_id>


-<pro_id id="[i]">

<product_name>Analog Watch</product_name>

<Link>Blah</Link>

<Image_link>Blah Again</Image_link>

<Original_price>2000</Original_price>

<Selling_price>1000</Selling_price>

<Discount>50%</Discount>

</pro_id>

</products>


Creating an XML from Python, after extracting some data from my web scrapper script.


How to set a variable value to pro_id, that changes with each iteration of for loop like pro_id.set(id,prod_ids[i]). prod_ids is a list of ids scrapped from a particular website.


Also I have set watches as string to category. Category="Watches", how to set it to some data extracted from web like Category.set = pro_type[i]. pro_type is a list of product types.


No comments:

Post a Comment