Skip to content
Advertisement

Selenium, issue getting ID of a generic tag and clicking

Issue: I cannot get a clickable variable that points the chosen anime title. The title is an tag that has a tag that contains the anime name. What I want to do is: 1)Get all anime that appear from the website 2)Select the anime that has the same name as the input variable “b” 3)Get the chosen anime title clickable to redirect to its page and datascrape it.

What is causing me a lot of issues is the selection of the right anime, because all anime titles only share the same class name and the “presence of the strong tag” and that doesn’t seem enough to get the title clickable

Website I use selenium on:

This is the full program code for the moment: from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By import time

JavaScript

I wanted to open the page by clicking the blue name of one of the anime that came up as result of the previus input on the searchbar

I AM VERY SORRY IF THIS EDIT DOESN’T STILL MAKE THE ISSUE CLEAR, english is not my native lenguage and I’m pretty new to programming too so its very difficult for me. I thank everyone that spent and (I wish) will spend time trying to help me; God bless you all

Advertisement

Answer

You don’t need to specify index when you use for in.

JavaScript

if you want to go to the page of the first anime that comes up as a result of the search

you can use code like this

JavaScript

Since we will no longer be looking for an element instead of a list, we can search it directly in driver.get without assigning it to a variable.

JavaScript

You can call the link in the ‘href’ element found in the anime result with the get_attribute method

When the element is searched before it is loaded, an error is received because the element is not found. For this, WebDriverWait is used, which is waiting for the element to be loaded.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement