Testing out various Xpaths but none seemed to be effective

I am trying to extract a score from the following URLs: shows a score of "10" displayed in an Octagon image, while has a score of "5".

Upon inspecting the elements, I found the score represented as:

<text y="100" dy="0.32em"><tspan x="100" text-anchor="middle">10</tspan></text>

I have been using Google Docs and the Importxml function with various Xpaths, but all are returning #N/A.

I have tried different Xpath variations such as:

//tspan

//tspan[1]

//text/tspan[1]

//text[1]/tspan[1]

//svg/text[1]/tspan[1]

I even attempted using the full xpath:

/html/body/div[1]/div/div/main/div/div/article/div[2]/div/main/div[1]/div[2]/section[1]/div[1]/div[1]/div/svg/text/tspan

Can anyone provide guidance on where I may be making a mistake?

The formula I am using in Google Docs is:

=IMPORTXML(A1,A2)

Where A1 is , and A2 is one of the Xpaths mentioned above

Answer №1

If you're looking to target specific elements, try the following xpath:

//*[@data-anchor='center']

Alternatively,

//*[@position='100']

Answer №2

If you're trying to extract data from a website that uses Javascript like Google Sheets, you won't have much luck. However, tools like Selenium can help you scrape the data effectively.

For those determined to use Google Sheets, consider utilizing the ImportfromWeb addon. Be aware that there are limitations on the number of requests in the free plan and remember to specify 'jsrendering' when setting it up.

To select the desired content, utilize the following XPath:

//div[contains(@class,"active")]/span

In cell C6, input the formula:

=IMPORTFROMWEB(C2;C3;B4:C4)

The output should resemble this:

https://i.sstatic.net/dfkBt.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to style the currently selected option element in a select dropdown?

I am trying to change the font color of specific option elements within a select dropdown by adding style="color: #D4D4D4". When I apply this style directly to an option element like <option value="TEST" style="color: #D4D4D4">TEST</option>, it ...

Issue with Bootstrap 5 dropdown menu extending beyond the viewport on the right side

The user dropdown in my code is cut off, even though I'm using Bootstrap 5. I came across an older article on stackoverflow suggesting to add .dropdown-menu-left or .dropdown-menu-right to the </ul>, but that didn't solve the issue for me. ...

While Xpath can be successfully located within Elements and Console, it encounters difficulty when attempting to be located during application execution

I'm currently enhancing my skills with Selenium Webdriver along with ChromeDriver, focusing on XPath. Below is the code snippet that I attempted to run: WebDriver driver; String baseURL = "http://youtube.com"; System.setProperty("webdr ...

Embed a hyperlink within an informational passage

I have a search box with Ajax functionality like this; And I want to customize the NotfindText message to display as: "No results found, but you can try advanced search from here" However, I am struggling to add the link. I do not have much knowledge abo ...

Arrange divs in vertical columns

My markup is fixed and I am only allowed to add <div> elements to the container. Here is the current structure: <div class="container"> <div class="box" id="box1">1</div> <div class="box" id="box2">2</div> < ...

combining: enhancing the value of the background-image property

Here is a mixin that I would like to modify: .a () {background-image: url(one.png);} I want to create a new class .b which inherits properties from .a, but also includes an additional background image layer, like this: .b { .a; ...

What is the process for sending an email to a designated recipient through an HTML form and then storing it as a record in an HTML table?

<!-- Placeorder part --> <div data-ng-show = "isPlaceOrder"> <div class = "col-lg-10" style = "margin-top:80px"> <div class="panel panel-primary"> <div class = "panel-heading">Drug Request Mail Sender</div&g ...

Implementing function invocation upon scroll bar click

I have a Div element with a scroll bar. When a user clicks the scroll bar, I want to call a function based on that click event. How can I achieve this? On the client side, I am using jQuery and on the server side, I am using PHP. I am familiar with makin ...

Encountering issues with clicking an element located using XPath in Scala Selenium webdriver

Trying to automate clicking on a menu item without a class or id proved challenging. The element was not clickable, resulting in an error. Sample Scala Code: val element = find(xpath("//tr[@aria-label='Show By ']")).get.underlying click on elem ...

How to load a URL into a div using jQuery and then update the div with new content?

I have a codeigniter view that I want to load into a div as an iframe using the following code: <script type='text/javascript'> $(document).ready(function (){ $('#divId').load('http://www.domain.oo/page.php?test=1); }); ...

Automate the process of interacting with Instagram buttons by utilizing selenium

Recently started dabbling in Python and attempting to create an Instagram bot using selenium. I'm struggling to make the code progress past the login button and 'not now' button. from time import sleep from selenium import webdriver browse ...

My div is currently being concealed by a jQuery script that is hiding all of its

Below is the current code snippet: jQuery(document).ready(function($) { $("ul.accordion-section-content li[id*='layers-builder'] button.add-new-widget").click(function() { $("#available-widgets-list div:not([id*='layers-widget']) ...

Can Selenium be executed from a <py-script> within an HTML file?

prefs = webdriver.ChromeOptions() prefs.add_experimental_option("detach", True) driver = webdriver.Chrome(ChromeDriverManager().install(), options=prefs) Following this code, it seems to stop running (It runs fine in a .py file so I believe all ...

Denied running the inline script in Redocly

Experimenting with redoc-cli (https://github.com/Redocly/redoc/) in order to generate static documentation. Unfortunately, encountered some stumbling blocks due to errors related to the Content-Security-Policy, which seems to be blocking JavaScript code ex ...

What impact does utilizing CSS 3D Transforms have on search engine optimization (SEO)?

Google emphasizes the importance of not hiding content, as it may not be counted by search engines. However, Google Cache has shown some discrepancies in understanding certain elements correctly. It's possible that what Google perceives as hidden migh ...

Determining the precise margin within a nested div structure

Hopefully, my description of a "nested div" was accurate. My current situation involves an image within a div structured like this: content -> content-inner -> column_left I'm struggling to start the image at 0 px (the extreme left side of th ...

Firefox not responding to mouse movements

I am experimenting with creating an "animation" using JavaScript's "mousemove" Check it out here This is the code I am currently using $("body").mousemove(function(e){ var wWidth = $("body").width()/2 var wHeight = $("body").height()/2 var posX; v ...

Ways to update row background color based on specific column values

I need to customize the background color of my table rows based on the value in the "Category" column. For example: Name Category Subcategory A Paid B C Received D If the Category value is 'Paid', I want the ro ...

HTML table row content should be aligned to the left side

I am attempting to align the data in the 'Address' column without any margin. I want it to start from the left since it's overflowing. You can find the HTML, CSS, and JS code here Even though I tried using <td align="left">..</td& ...

What is the best way to align this form perfectly in Bootstrap 4?

HTML <div class="container-fluid background"> <div class="row"> <!-- background effect --> <div id="particles-js"> <div class="login col-12"> <form class="login-form" method="post" action=""> ...