I am trying to take some information I got from a webpage and write one of the variables to a file however I am having no luck it is probably very easy but I'm lost. Here is an example of one of the rows there are 1253 rows.
<div class='entry qual-5 used-demoman slot-head bestprice custom' data-price='3280000' data-name="Kill-a-Watt Allbrero" data-quality="5" data-australium="normal" data-class="demoman" data-particle_effect="56" data-paint="" data-slot="cosmetic" data-consignment="consignment">
I am after the field called data-name it is not at the same spot in each row. I tried this but it did not work
mfile=open('itemlist.txt','r')
mfile2=open('output.txt','a')
for row in mfile:
if char =='data-name':
mfile2.write(char)
Edit 1:
I made an example file of 'hello hi peanut' if did:
for row in mfile:
print row.index('hello')
it would print 0 as expected however when I changed the hello to hi it didnt return 1 it returned nothing.
charis not defined in your code. You could userow.index('data-name')to figure out where the attribute begins. Then you canindexagain starting from that index to find the two quotation marks and use string manipulation to extract the value.