![]() |
|
[Python] Selenium: How can I organize items with subitems within? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Selenium: How can I organize items with subitems within? (/showthread.php?tid=5843664) |
Selenium: How can I organize items with subitems within? - Hydra - Jun 2, 2018 So I'm using Selenium (Firefox WebDriver) in Python to go to a link, login, then go to another page after login. On this page is a grid of items. Each item has 3 subitems: link (the item is clickable), image, and title (like a description). I'm able to pull all the items using a for-in loop into a variable. Then I just do all_items[:3] to get the first 3. However I can't figure out how to further narrow it by grabbing all_items[2] 's image only. Basically I want to organize it into a two-dimensional array if I'm understanding it correctly. My end goal is to be able to do these outputs(not actual code): Code all_items[4][2] = https://example.com/image.png4 being item #4, 2 being the image subitem of the 3 (link, image, title) I've been googling for a while. I've been working on this personal project for a bit now and I've made good progress for the little Python I know and I've managed to get a lot of progress thanks to researching. However, I'm stuck on this part and can't figure it out. I have two versions I've been messing with but can't figure out how to go further. V1 - I found similar code to this online and modified it to work for my use. This is the farthest I can get in terms of controlling the index. I'm able to call items[:3] for the first 3 items but I can't control the subitems. Code items = [{"Link": item.find_element_by_class_name('ember-view').get_attribute('href'), "Title": item.find_element_by_class_name('achievement-title').text, "Image": item.find_element_by_class_name('main-image').get_attribute('src')} for item in all_items]V2 - This probably would work better than V1 but I can't figure out how to throw it into a two-dimensional array now. It does output it how I want but I can't control which item index it outputs. Code for item in all_items:Any help would be greatly appreciated. Thanks a bunch! RE: Selenium: How can I organize items with subitems within? - Vanagander - Jun 2, 2018 Edit: noticed afterwards you wanted a 2 dimensional array(?), this is done with a multidimensional list If I understood you correctly you might have: PHP Code To only get all the images (or sites/description just change the index): PHP Code If you only want one specific image from the second example: PHP Code RE: Selenium: How can I organize items with subitems within? - Hydra - Jun 2, 2018 I'll test that out and see what I can get going, thanks for the help! Appreciate the examples. |