vader 0 Posted October 6, 2010 Report Share Posted October 6, 2010 I'm having some issues pulling data from a CSV to fill in some html forms. The problem appears to be with how the CSV is being read. For example, data in a typical CSV looks like this: row1_item1, row1_item2, row1_item3, row1_item4row2_item1, row2_item2, row2_item3, row2_item4row3_item1, row3_item2, row3_item3, row3_item4 I'm trying to fill in 4 form fields, but I'm getting some quirks when Ubot cycles to the 4th field. Here is what I get the first loop through for values for each field (using the sample format above as an example): 1. row1_item12. row1_item23. row1_item34. row1_item4 row2_item1 .....so, when it gets to the end of a row (or what should be the end), it grabs the 4th value, but also combines it with value1 from the next row. Is this because the 4th item doesn't have a comma delimiter at the end? From what I can tell, it's not standard CSV format to have a comma after the last value in each row. So, I'm a little puzzled by why it's screwing up the last item in each row. Any tips are greatly appreciated.Thanks. Quote Link to post Share on other sites
MiriamMB 63 Posted October 6, 2010 Report Share Posted October 6, 2010 I'm having some issues pulling data from a CSV to fill in some html forms. The problem appears to be with how the CSV is being read. For example, data in a typical CSV looks like this: row1_item1, row1_item2, row1_item3, row1_item4row2_item1, row2_item2, row2_item3, row2_item4row3_item1, row3_item2, row3_item3, row3_item4 I'm trying to fill in 4 form fields, but I'm getting some quirks when Ubot cycles to the 4th field. Here is what I get the first loop through for values for each field (using the sample format above as an example): 1. row1_item12. row1_item23. row1_item34. row1_item4 row2_item1 .....so, when it gets to the end of a row (or what should be the end), it grabs the 4th value, but also combines it with value1 from the next row. Is this because the 4th item doesn't have a comma delimiter at the end? From what I can tell, it's not standard CSV format to have a comma after the last value in each row. So, I'm a little puzzled by why it's screwing up the last item in each row. Any tips are greatly appreciated.Thanks. You need a comma delimiter to discern item 3 from item four. I don't think you need a comma after the last value. The format you have it it should be working fine, unless you are missing the comma between row1_item4 and row2_item1 somehow...? Quote Link to post Share on other sites
vader 0 Posted October 6, 2010 Author Report Share Posted October 6, 2010 You need a comma delimiter to discern item 3 from item four. I don't think you need a comma after the last value. The format you have it it should be working fine, unless you are missing the comma between row1_item4 and row2_item1 somehow...? I don't think I'm missing any commas. My input file is being created by Excel (Save as > CSV), so I'm not manually inputting any commas. Excel's default CSV format is to organize things like I originally listed (no comma after the last value in a row). Since this is standard CSV formatting, I'm puzzled as to why my row1 and row2 data is getting mixed together when I put it into the form fields. Perhaps I'm just missing a Ubot command somewhere in my loop that'll solve the problem (I'm very new to Ubot still). Thanks. Quote Link to post Share on other sites
IRobot 43 Posted October 6, 2010 Report Share Posted October 6, 2010 Hi vader, I don't think I'm missing any commas. My input file is being created by Excel (Save as > CSV), so I'm not manually inputting any commas. Excel's default CSV format is to organize things like I originally listed (no comma after the last value in a row). Since this is standard CSV formatting, I'm puzzled as to why my row1 and row2 data is getting mixed together when I put it into the form fields. Remove the spaces from the CSV file. Perhaps I'm just missing a Ubot command somewhere in my loop that'll solve the problem (I'm very new to Ubot still).Try this: reader.zip 1 Quote Link to post Share on other sites
vader 0 Posted October 6, 2010 Author Report Share Posted October 6, 2010 @IRobot Thanks a lot for that code!!...my bot is now functioning properly. My code was pretty close to yours, but the one thing I was missing (which may have been the cause of my error) was the "Clear List %row" at the beginning of the loop. Can you explain why this is needed? I "assumed" that clear list would clear everything out and I'd just keep looping through Row 1 data over and over....apparently I just don't understand how clear list works. Anyway, thanks again for providing the sample code, it was a HUGE help and big timesaver for me. Cheers! Quote Link to post Share on other sites
IRobot 43 Posted October 6, 2010 Report Share Posted October 6, 2010 My code was pretty close to yours, but the one thing I was missing (which may have been the cause of my error) was the "Clear List %row" at the beginning of the loop. Can you explain why this is needed? I "assumed" that clear list would clear everything out and I'd just keep looping through Row 1 data over and over....apparently I just don't understand how clear list works.No problem mate. The clear list %row is required because the code loops through the row items in the CSV file, and as the code uses variables to access each row item (which is a field value), the list needs to be cleared. Quote Link to post Share on other sites
vader 0 Posted October 7, 2010 Author Report Share Posted October 7, 2010 No problem mate. The clear list %row is required because the code loops through the row items in the CSV file, and as the code uses variables to access each row item (which is a field value), the list needs to be cleared. Ok, got it. Thanks. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.