Issue
I've recently been undertaking a personal project to improve my programming. I'm relatively new to Python.
What i'm trying to do is scrape some data( about 100-200 items) from a website. I've managed to do it for some elements but not for others. Selenium can't seem to recognize that class name.
<span ng-class="$ctrl.className"> Alpha Esports </span>
I believe the $ctrl has to do with angularjs. The span tag is contained in a div tag, as seen here:
<div class="ui-scoreboard-coupon-template__content--vertical-container"> <!----><div class="ui-scoreboard-coupon-template__content--vertical-aligner" ng-if="!$ctrl.viewModel.isAmericanEvent"> <div> <!----><div class="ui-scoreboard-coupon-template__cell__spacer" ng-if="!$ctrl.viewModel.inPlay"></div><!----> <!----> <div class="ui-scoreboard-coupon-template__cell"> <ui-scoreboard-runner class="ui-scoreboard-runner ui-scoreboard-runner__home" name="$ctrl.viewModel.home">
<span ng-class="$ctrl.className"> Alpha Esports </span> </ui-scoreboard-runner> </div> </div> <div class="ui-scoreboard-coupon-template__row__space"></div> <div> <!----><div class="ui-scoreboard-coupon-template__cell__spacer" ng-if="!$ctrl.viewModel.inPlay"></div><!----> <!----> <div class="ui-scoreboard-coupon-template__cell"> <ui-scoreboard-runner class="ui-scoreboard-runner ui-scoreboard-runner__away" name="$ctrl.viewModel.away">
<span ng-class="$ctrl.className"> G-Rex </span> </ui-scoreboard-runner> </div> </div> </div><!----> <!----> </div>
I've thought about using the xpath but it differs for each data piece and I don't know how to make 'dynamic' xpaths. When I try to use the class name of a parent tag, it does not return any element. I've tried all of the class names that are present in the code excerpt above.
teams = []
teams = driver.find_elements_by_class_name("ui-scoreboard-coupon-template__content--vertical-container")
Finally, I thought the $ctrl might've been initialized to something earlier in the code but this is the first use of it:
<div class="collapsed-header collapsed-header--show" ng-show="$ctrl.showCollapsedHeader" ng-class="{'collapsed-header--show': $ctrl.showCollapsedHeader}">
<div class="frame-layout">
<div class="left-hand-side">
<a class="collapsed-header__logo" ng-href="/bet" href="/bet">
<svg class="collapsed-header__img">
<use xlink:href="sprite_9c5b742d050f5c4b58fe55f82f78c576.svg#logos-header_logo-usage"></use>
</svg>
</a>
</div>
<div class="center"></div>
<div class="right-hand-side"></div>
</div>
</div>
Any tips regarding what to research/read up on would be much appraciated as I'm a bit overwhelmed by the angularjs concepts and selenium implementation.
Solution
I have tried with XPath
and it works.Please try and let me know.
print(driver.find_element_by_xpath("//ui-scoreboard-runner[@class='ui-scoreboard-runner ui-scoreboard-runner__home']/span").text)
Answered By - KunduK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.