I am trying to find product names in an xml file i downloaded. I have figured out how to display every result using a while loop. My problem is, i want to only display the first 10 results. Also, i need be able to call each result individually.
For example: print(read_xml_code.start_tag_5) would print the 5th product in the XML file. print(read_xml_code.start_tag_10) would print the 10th
here is my code so far:
# Define the Static webpage XML file
static_webpage_1 = 'StaticStock/acoustic_guitar.html'
def Find_static_webpage_product_name():
# Open and read the contents of the first XML file
read_xml_code = open(static_webpage_1, encoding="utf8").read()
# Find and print the static page title.
start_tag = '<title><![CDATA['
end_tag = ']]></title>'
end_position = 0
starting_position = read_xml_code.find(start_tag, end_position)
end_position = read_xml_code.find(end_tag, starting_position)
while starting_position != -1 and end_position!= -1:
print(read_xml_code[starting_position + len(start_tag) : end_position]+ '\n')
starting_position = read_xml_code.find(start_tag, end_position)
end_position = read_xml_code.find(end_tag, starting_position)
#call function
Find_static_webpage_product_name()