css-selectors

CSS to apply if 2 elements exist

纵饮孤独 提交于 2020-06-29 06:41:10
问题 Given the following HTML markup, I want to apply (S)CSS only when 2 of the same elements exist (not when 1 exists). I don't want to use JavaScript to count the number of elements and apply another class, however, I feel this is the only approach. div { a + a { // I want to apply styles to both a tags, not just the second one // WHEN 2 a tags exists } } <div> <a href="/">Home</a> <a href="/about">About</a> </a> 回答1: You can use "quantity queries". For exactly TWO... a:nth-last-child(n+2):nth

Instagram user following automation project

假如想象 提交于 2020-06-29 03:56:26
问题 Trying to automate the process by avoiding clicking on the already requested or followed users. Instagram allows following of max. 7500 user a day. I would like to limit it to that number as well as avoid what I described in the first sentence. My code: List<WebElement> clickOnFollowButton = driver.findElements(By.xpath("//button[contains(text(),'Follow')]")); for (int i = 0; i < clickOnFollowButton.size() ; i++) { WebElement element = driver.findElements(By.xpath("//button[contains(text(),

Extract class name in scrapy

依然范特西╮ 提交于 2020-06-27 13:54:27
问题 I am trying to scrape rating off of trustpilot.com. Is it possible to extract a class name using scrapy? I am trying to scrape a rating which is made up of five individual images but the images are in a class with the name of the rating for example if the rating is 2 starts then: <div class="star-rating count-2 size-medium clearfix">... if it is 3 stars then: <div class="star-rating count-3 size-medium clearfix">... So is there a way I can scrape the class count-2 or count-3 assuming a

How to send text to the search field through Selenium and Python

北慕城南 提交于 2020-06-27 12:06:47
问题 I am trying to pass arguments to a search text in a HTML code using Selenium in Python: I am working on the following HTML code: </form><form class="search-box-inner"> <div class="input-container"> <input type="text" class="typeahead search-box-input left" autocomplete="off" placeholder="Search ratings, research, analysts, and more..." maxlength="900"></div> </form> The code does not have id or name. It has elements by class only. I tried the following self.driver.find_elements_by_class_name(

How to send text to the search field through Selenium and Python

给你一囗甜甜゛ 提交于 2020-06-27 12:05:01
问题 I am trying to pass arguments to a search text in a HTML code using Selenium in Python: I am working on the following HTML code: </form><form class="search-box-inner"> <div class="input-container"> <input type="text" class="typeahead search-box-input left" autocomplete="off" placeholder="Search ratings, research, analysts, and more..." maxlength="900"></div> </form> The code does not have id or name. It has elements by class only. I tried the following self.driver.find_elements_by_class_name(

CSS pseudo-class vs. pseudo-selector

早过忘川 提交于 2020-06-25 01:28:09
问题 This is a bit of a pedantic question, but perhaps worth asking. Is there, mechanically, a difference between a pseudo-class and a pseudo-selector in CSS? We use the term interchangeably around here, but it seems that there's a reason for the two terms. Is there any use to differentiating the two? 回答1: A pseudo-class is a specified thing, while pseudo-selector is a made up word. (Meanwhile, a pseudo-class matches an element when certain conditions are met (e.g. the mouse is pointing at it, or

How to find an element with respect to the user input using Selenium and Python?

做~自己de王妃 提交于 2020-06-23 12:54:49
问题 The following is the HTML structure: <div class='list'> <div> <p class='code'>12345</p> <p class='name'>abc</p> </div> <div> <p class='code'>23456</p> <p class='name'>bcd</p> </div> </div> And there is a config.py for user input. If the user input 23456 to config.code, how can the selenium python select the second object? I am using find_by_css_selector() to locate and select the object, but it can only select the first object, which is Code='12345' . I tried to use find_by_link_text() , but

How to find an element with respect to the user input using Selenium and Python?

送分小仙女□ 提交于 2020-06-23 12:51:06
问题 The following is the HTML structure: <div class='list'> <div> <p class='code'>12345</p> <p class='name'>abc</p> </div> <div> <p class='code'>23456</p> <p class='name'>bcd</p> </div> </div> And there is a config.py for user input. If the user input 23456 to config.code, how can the selenium python select the second object? I am using find_by_css_selector() to locate and select the object, but it can only select the first object, which is Code='12345' . I tried to use find_by_link_text() , but

How to retrieve partial text from a text node using Selenium and Python

别来无恙 提交于 2020-06-23 12:21:11
问题 I want to get only " text ... " not using .split() or index slicing HTML: <a class="call_recipe" href="/recipes/2913"> " text ... " <strong> something~ </strong> </a> HTML Snapshot: 回答1: To print text ... you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies: Using CSS_SELECTOR and childNodes : print(driver.execute_script('return arguments[0].firstChild.textContent;', WebDriverWait(driver, 20).until(EC.visibility_of

How to retrieve partial text from a text node using Selenium and Python

霸气de小男生 提交于 2020-06-23 12:19:59
问题 I want to get only " text ... " not using .split() or index slicing HTML: <a class="call_recipe" href="/recipes/2913"> " text ... " <strong> something~ </strong> </a> HTML Snapshot: 回答1: To print text ... you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies: Using CSS_SELECTOR and childNodes : print(driver.execute_script('return arguments[0].firstChild.textContent;', WebDriverWait(driver, 20).until(EC.visibility_of