Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Problems getting an element from a html

$
0
0

I'm trying to use Selenium to (legally) scrape data from a website. I tried the code, but nothing appears as result. I'd like to obtain the data and see what I've done at the button before I show you how the HTML appears.

I just need to get "31 954 kr" from the hmtl.enter image description here

Full html:

<article class="c-product-tile h-full relative product-}"><a class="c-product-tile__link" tabindex="0" title="Balance  Spisebord" ng-click="$ctrl.handleClick($event)" pdp-link="c/03-102-01_10991348" outlet="$ctrl.product.type === 'outletProduct'" target="_self" href="/nb-no/mot-oss/butikker/online-outlet/produkt/c/03-102-01_10991348/"></a><div class="flex h-full flex-col relative"><div class="c-product-tile__image bg-wild-sand px-6 py-28 mb-4 relative md:px-14 md:py-32 lg:px-12 lg:py-60"><!----><div class="c-aspect-ratio-16x9 anim-fade-in  scale-" ng-if="::$ctrl.product.type !== 'legs' || !$ctrl.product.useLegImages" style=""><tile-image base-src="/products/03-102-01_10991348.webp" template="tileImageProductTile" is-product-image="true" move-pressmode-btn=".product- .c-product-tile__image" cachebust="0" mode="pad" aspect-ratio="16x9" default-on-error-url="/layout/images/produkt-default-medium-1.png" bgcolor="transparent" description="Balance  Spisebord"><!----><div class="c-tile-image" ng-if="$ctrl.readyForLoad" style=""><!----><!----><img src="/layout/images/7x3.gif" lazy-src="https://images.bolia.com/cdn-cgi/image/background=transparent,fit=pad,width=500,format=auto,height=281,quality=81/products/03-102-01_10991348.webp?v=0" lazy-srcset="https://images.bolia.com/cdn-cgi/image/background=transparent,fit=pad,width=340,format=auto,height=191,quality=81/products/03-102-01_10991348.webp?v=0 340w,https://images.bolia.com/cdn-cgi/image/background=transparent,fit=pad,width=540,format=auto,height=303,quality=81/products/03-102-01_10991348.webp?v=0 540w" load-immediately="$ctrl.loadImmediately" sizes="153px" alt="Balance  Spisebord" on-error="/layout/images/produkt-default-medium-1.png" ng-class="{'tile-image__takeover' : $ctrl.takeOver, '': $ctrl.cssClass !== undefined}" srcset="https://images.bolia.com/cdn-cgi/image/background=transparent,fit=pad,width=340,format=auto,height=191,quality=81/products/03-102-01_10991348.webp?v=0 340w,https://images.bolia.com/cdn-cgi/image/background=transparent,fit=pad,width=540,format=auto,height=303,quality=81/products/03-102-01_10991348.webp?v=0 540w"></div><!----></tile-image></div><!----><div class="absolute pin my-6"><div class="absolute pin-t pin-l"><!----><!----></div><!----><div class="absolute pin-l pin-b pin-r flex justify-between"><!----><div class="pl-2 pr-4 w-full flex flex-wrap-reverse flex-col justify-self-end justify-end"><!----><!----><!----><!----></div></div></div></div><!----><div ng-if="!$ctrl.noPrice" class="" style=""><!----><!----><div ng-if="::$ctrl.product.type === 'outletProduct'" class="mb-4"><p class="c-product-tile__title c-text-caption m-0 font-bold"><span class="c-text-caption" ng-bind="$ctrl.product.title">Balance  Spisebord</span></p><p class="c-text-caption truncate m-0 hidden md:block" ng-bind="::$ctrl.product.designInformation">Brun marmor</p><p class="c-text-caption m-0" ng-bind="::$ctrl.product.details">God stand</p></div><!----><!----><div ng-if="::$ctrl.showFromPrice() || $ctrl.showSalesPrice()" class="m-0 flex flex-wrap items-baseline"><!----><p ng-if="!$ctrl.isMyBoliaBoostDiscount()" class="flex flex-wrap c-text-caption m-0"><!----><span ng-if="$ctrl.showSalesPrice()" class="flex flex-wrap items-baseline"><!----><span ng-if="$ctrl.showListPrice()" class="mr-3 font-bold" ng-class="{'font-bold':  $ctrl.showListPrice()}" ng-bind="::$ctrl.product.salesPrice.amount">31&nbsp;954 kr.</span><!----><span ng-class="{'line-through': $ctrl.showListPrice()}" class="mr-3 line-through" ng-bind="::$ctrl.product.listPrice.amount">63&nbsp;909 kr.</span><!----><span ng-if="$ctrl.showDiscountText()" ng-style="::$ctrl.splashLabelService.labelStyle()" class="c-text-caption mr-3 flex items-center my-0 px-2 py-1 bg-brandy" style="background: rgb(225, 221, 212); color: rgb(0, 0, 0);">                            Spar 50%</span><!----></span><!----><!----></p><!----><!----><!----></div><!----><!----><!----><!----></div><!----><!----></div></article>

My python code (selenium)

    from selenium import webdriver    from selenium.webdriver.common.by import By    from selenium.webdriver.support.ui import WebDriverWait    from selenium.webdriver.support import expected_conditions as ECdriver = webdriver.Chrome()driver.get("wwww.scrapedatafromhere.com")element = WebDriverWait(driver, 10).until(    EC.visibility_of_element_located((By.XPATH, "(//article[contains(@class, 'c-product-tile')]//p[contains(@class, 'c-product-tile__title')]/span)[1]")))text = element.textprint("Text:", text)

The result:empty (no error)What I am doing wrong here?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>