{"id":9581,"date":"2020-02-28T10:10:22","date_gmt":"2020-02-28T04:40:22","guid":{"rendered":"http:\/\/ivyproschool.com\/blog\/?p=9581"},"modified":"2021-06-11T12:08:21","modified_gmt":"2021-06-11T06:38:21","slug":"how-to-use-xpath-for-web-scraping-with-selenium","status":"publish","type":"post","link":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/","title":{"rendered":"How to use XPath for Web Scraping with Selenium"},"content":{"rendered":"<p><a href=\"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9595 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final-300x187.png\" alt=\"XPath Selenium cover image\" width=\"300\" height=\"187\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final-300x187.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final-768x478.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final-1024x637.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Web scraping is a commonly used technology existing for a couple of decades now. We use programming languages like Python with libraries namely Beautiful Soup, Selenium, Scrapy, etc. or R with Rvest package for web scraping. Other web scraping tools are also available. A vivid explanation of how we do web scraping using Python is provided in the article named <a href=\"https:\/\/www.opencodez.com\/web-development\/web-scraping-using-beautiful-soup-part-1.htm\">Web Scraping using Beautiful Soup<\/a>.\u00a0 Further to the above, in this article, we are going to understand XPath and how it can be used to navigate through the HTML document for Web Scraping with Selenium to reach the target nodes using Python.<\/p>\n<h2>Our Target Website &#8211;<\/h2>\n<p>Let us consider the webpage of a very popular Indian daily English newspaper Telegraph <a href=\"https:\/\/www.telegraphindia.com\/\">https:\/\/www.telegraphindia.com\/<\/a><\/p>\n<h2>What Library are we using &#8211;<\/h2>\n<p>We are using the robust <a href=\"https:\/\/selenium-python.readthedocs.io\/locating-elements.html\">Selenium web driver<\/a> to navigate through the Telegraph website using XPath.<\/p>\n<h2>What is XPath &#8211;<\/h2>\n<p>The full form of XPath is XML Path language. It is a very popular Web Technology and W3C standard. We can access precise information in an XML\/HTML document using these concise and powerful XPath statements.<\/p>\n<h2>Understanding the structure of XPath &#8211;<\/h2>\n<p>First of all, let us see how can we find XPath of any element. We are using Mozilla Firefox as our browser. Our target element is the &#8220;Opinion&#8221; section on the web page. The steps to select the XPath for this element is as follows &#8211;<\/p>\n<ol>\n<li>Right-click on the &#8216;opinion&#8217; section on the web page<\/li>\n<li>select inspect element<\/li>\n<li>The HTML code for this element will be highlighted in blue<\/li>\n<li>Right-click on the blue portion again<\/li>\n<li>Click on copy and select the XPath option<\/li>\n<li>Paste this on a text file. The path shows\u00a0 \/html\/body\/section\/div[1]\/div[2]\/div[2]\/div\/a<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-9584\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/XPath-inspect-element_2-1-300x223.png\" alt=\"XPath Opinion element\" width=\"300\" height=\"223\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/XPath-inspect-element_2-1-300x223.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/XPath-inspect-element_2-1-768x572.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/XPath-inspect-element_2-1-1024x762.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/XPath-inspect-element_2-1.png 1025w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The path shown above is called the <strong>absolute path<\/strong> that is the detailed path across the nodes to reach the target node. The absolute path starts with a &#8216;\/&#8217; which means starting the search from the root element. Another way to represent is by using a <strong>relative path<\/strong> in which we construct a shorter path to the target node. The absolute path for the &#8216;opinion&#8217; is \/\/section\/div[1]\/div[2]\/div[2]\/div\/a. Here we have replaced the &#8216;\/html\/body&#8217; tags with &#8216;\/\/&#8217; to shorten the path.<\/p>\n<p>There are other ways to represent an XPath using the Selenium selector. Let us take a look at them one by one.<\/p>\n<h3 class=\"fusion-responsive-typography-calculated\" data-lineheight=\"23.9333px\" data-fontsize=\"18\">Tag \u2013 Attribute \u2013 Value Trio<\/h3>\n<p><strong>Syntax:<\/strong> \/\/tag[@attribute=\u2019value\u2018]<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-9583\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/fourline-300x125.png\" alt=\"Fourlines\" width=\"300\" height=\"125\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/fourline-300x125.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/fourline-768x319.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/fourline-1024x425.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/fourline.png 1736w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>If you take a look at the screenshot above, we aim at identifying all the elements &#8216;a&#8217; with attribute class = &#8216;frontLine&#8217;. The XPath command for this element will be as follows.<\/p>\n<p>[php] \/\/a[@class=&#8217;fourLine&#8217;] [\/php]<\/p>\n<p>The command means we are looking for attribute class with value &#8216;fourLines&#8217; in the element &#8216;a&#8217;<\/p>\n<h3 class=\"fusion-responsive-typography-calculated\" data-lineheight=\"23.9333px\" data-fontsize=\"18\">Contains<\/h3>\n<p><strong>Syntax:<\/strong> \/\/tag[contains(@attribute, &#8216;value&#8217;)]<\/p>\n<p>Another XPath Selenium<strong>\u00a0<\/strong>locator which is very useful in identifying attributes is &#8216;contains&#8217;. Let us see how to use this command with an example.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9585 size-medium\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/contains-e1582717801938-300x213.png\" alt=\"XPath Selenium locator contains example\" width=\"300\" height=\"213\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/contains-e1582717801938-300x213.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/contains-e1582717801938-768x545.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/contains-e1582717801938-1024x727.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/contains-e1582717801938.png 1257w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>In the above screenshot, we want to locate all the tag &#8216;ul&#8217; in which its attribute class contains &#8216;headImage&#8217; in its value. The XPath command will be as follows. (We are going to use this scenario at other places in the article as well)<\/p>\n<p>[php]\u00a0 \/\/ul[contains(@class,&#8217;headImage&#8217;)]\u00a0 [\/php]<\/p>\n<h3>Starts With<\/h3>\n<p><strong>Syntax:<\/strong> \/\/tag[starts-with(@attribute, &#8216;value&#8217;)]<\/p>\n<p>This XPath Selenium locator is very useful when the attribute value is too long or changes dynamically. Using the same scenario as in the above-mentioned point, we can create an XPath comprising of &#8216;starts-with&#8217; as follows.<\/p>\n<p>[php]\u00a0 \/\/ul[starts-with(@class,&#8217;listing&#8217;)]\u00a0 [\/php]<\/p>\n<h3>Chained Declarations<\/h3>\n<p><strong>Syntax:<\/strong> \/\/tag[XPath Statement-1]\/\/tag[XPath Statement-2]<\/p>\n<p>Multiple XPath can be chained with \/\/ (double slash) to gain more accuracy and penetration through nodes and attributes. Going back to the same scenario, we want to identify all the links (href) associated with the ul element. The XPath command will be as follows.<\/p>\n<p>[php]\u00a0 \/\/ul[@class =&#8217;listing-withImage headImage&#8217;]\/\/a[@href]\u00a0 [\/php]<\/p>\n<h3>Operator Or<\/h3>\n<p><strong>Syntax:<\/strong> \/\/tag[XPath Statement-1\u00a0or\u00a0XPath Statement-2]<\/p>\n<table border=\"1\" width=\"293\" cellspacing=\"4\" cellpadding=\"4\">\n<tbody>\n<tr>\n<td><strong>A<\/strong><\/td>\n<td><strong>B<\/strong><\/td>\n<td><strong>Result<\/strong><\/td>\n<\/tr>\n<tr>\n<td>False<\/td>\n<td>False<\/td>\n<td>No Element<\/td>\n<\/tr>\n<tr>\n<td>True<\/td>\n<td>False<\/td>\n<td>Returns A<\/td>\n<\/tr>\n<tr>\n<td>False<\/td>\n<td>True<\/td>\n<td>Returns B<\/td>\n<\/tr>\n<tr>\n<td>True<\/td>\n<td>True<\/td>\n<td>Returns Both<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Another flexibility provided by the XPath Selenium locator is that we can give two XPath statements with an &#8216;or&#8217; operator. The output follows the above tabular result. An example command to identify attribute class with text value &#8220;fourLine&#8221; and &#8220;threeLine&#8221; is as follows.<\/p>\n<p>[php]\u00a0 \/\/a[@class=&#8217;fourLine&#8217; or @class=&#8217;threeLine&#8217;]\u00a0 [\/php]<\/p>\n<h3>Operator And<\/h3>\n<p><strong>Syntax:<\/strong> \/\/tag[XPath Statement-1 and XPath Statement-2]<\/p>\n<table border=\"1\" width=\"293\" cellspacing=\"4\" cellpadding=\"4\">\n<tbody>\n<tr>\n<td><strong>A<\/strong><\/td>\n<td><strong>B<\/strong><\/td>\n<td><strong>Result<\/strong><\/td>\n<\/tr>\n<tr>\n<td>False<\/td>\n<td>False<\/td>\n<td>No Element<\/td>\n<\/tr>\n<tr>\n<td>True<\/td>\n<td>False<\/td>\n<td>No Element<\/td>\n<\/tr>\n<tr>\n<td>False<\/td>\n<td>True<\/td>\n<td>No Element<\/td>\n<\/tr>\n<tr>\n<td>True<\/td>\n<td>True<\/td>\n<td>Returns Both<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>The various output based on the boolean value of the 2 XPaths is provided in the table above. An example command prepared for this website is as follows.<\/p>\n<p>[php]\u00a0 \/\/a[@class=&#8217;threeLine&#8217; and contains(@href,&#8217;\/india\/&#8217;)]\u00a0 [\/php]<\/p>\n<p>With this, we are trying to identify all the &#8216;a&#8217;\u00a0 elements that contain an attribute named class with value &#8216;threeLine&#8217; and another attribute href which contains a text &#8216;\/india\/&#8217;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-9587\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/class_threeLine-300x203.png\" alt=\"XPath And operator\" width=\"300\" height=\"203\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/class_threeLine-300x203.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/class_threeLine-768x519.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/class_threeLine-1024x692.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/class_threeLine.png 1152w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>Numerical Predicate<\/h3>\n<p><strong>Syntax:<\/strong> \/\/tag[position()=1]<\/p>\n<p>We can locate nodes based on numerical functions like &#8216;<strong>position<\/strong>&#8216; provided as an example in the above syntax. For the Telegraph website, we can use any tag and find the position desired (provided that position of the tag exists). For example, for the ul tag that we saw in a previous example, we can point to all the ul tag wherever it has the first position in succession of its relative parent div tag in the tree structure of the HTML doc.<\/p>\n<p>[php]\u00a0 \/\/div\/ul[position()=1]\u00a0 [\/php]<\/p>\n<p>We can use another function &#8220;<strong>last<\/strong>&#8221; and identify all the &#8216;ul&#8217; tags positioned last in the relative path.<\/p>\n<p>[php]\u00a0 \/\/ul[last()]\u00a0 [\/php]<\/p>\n<p>&#8216;<strong>Count<\/strong>&#8216; is a very useful predicate that can be used to count the number of attributes a tag contains. For example, if we want to identify the element &#8216;a&#8217; in all the div tags which have a total count of attributes more than 5, we can use the below command.<\/p>\n<p>[php]\u00a0 \/\/div[count(.\/@*)&gt;5]\/\/a\u00a0 [\/php]<\/p>\n<h2>Node Relations &#8211;<\/h2>\n<p>Another interesting way to create XPath is by using Node Relations that follows the family tree analogy. It is represented as <span class=\"codeLabel\">node1\/<\/span><i><span class=\"codeLabel\">relation<\/span><\/i><span class=\"codeLabel\">::node2.<\/span> In other words, any node essentially maintains several relations with other nodes, for example, ancestor, child, descendant, parent, sibling, etc. We are going to mention commands for some of these relations.<\/p>\n<p>[php]\u00a0 \/\/div[count(.\/@*)&gt;5]\/\/child::ul\u00a0 [\/php]<\/p>\n<p>This command means we are trying to point out all the &#8216;ul&#8217; nodes which are a child to the &#8216;div&#8217; tags having a count of attributes more than 5.<\/p>\n<p>[php]\u00a0 \/\/div[count(.\/@*)&gt;5]\/\/ancestor::div\u00a0 [\/php]<\/p>\n<p>The above command points to all the div tag which is the ancestor to the &#8216;div&#8217; tags having a count of attributes more than 5.<\/p>\n<p>[php]\u00a0 \/\/div\/\/preceding::li\u00a0 [\/php]<\/p>\n<p>Here we are going to locate all the &#8216;list&#8217; tag which is preceding to the div tag.<\/p>\n<h2>What is Selenium &#8211;<\/h2>\n<p>Selenium is a Web Browser Automation Tool. With the use of Selenium, we can browse a website just as a human would. We can click buttons, automate logins, give search text inputs and perform automation of several testing tasks as well.<\/p>\n<h2>Selenium XPath Commands &#8211;<\/h2>\n<p>We have discussed so many different ways to prepare the XPath command pointing to specific nodes and attributes. However, it is incomplete without understanding what command to use to extract all the elements the XPath points to. Selenium package provides us with commands to extract a single element or multiple elements in the form of a list from the XPath location. To name a few, commands are<\/p>\n<ul>\n<li><cite>find_element_by_id<\/cite><\/li>\n<li><cite>find_element_by_name<\/cite><\/li>\n<li><cite>find_element_by_xpath<\/cite><\/li>\n<li><cite>find_elements_by_name<\/cite><\/li>\n<li><cite>find_elements_by_xpath<\/cite><\/li>\n<\/ul>\n<p>The commands of our interest are <strong>find_element_by_xpath<\/strong> and <strong>find_elements_by_xpath<\/strong>. Considering we are working on the Chrome browser with Chromedriver.exe installed, our complete commands for most of the scenarios discussed above will look like below.<\/p>\n<p>[php]<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/section\/div[1]\/div[2]\/div[2]\/div\/a&quot;)<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/a[@class=&#8217;fourLine&#8217;]&quot;)<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/ul[contains(@class,&#8217;headImage&#8217;)]&quot;)<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/ul[@class =&#8217;listing-withImage headImage&#8217;]\/\/a[@href]&quot;)<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/a[@class=&#8217;threeLine&#8217; and contains(@href,&#8217;\/india\/&#8217;)]&quot;)<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/div[count(.\/@*)&gt;5]\/\/a&quot;)<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/div[count(.\/@*)&gt;5]\/\/ancestor::div&quot;)<\/p>\n<p>driver.find_elements_by_xpath(&quot;\/\/div\/\/preceding::li&quot;)<\/p>\n<p>[\/php]<\/p>\n<h2>Conclusion &#8211;<\/h2>\n<p>Python definitely provides this very powerful Selenium Webdriver with which we can even automate web scraping. We hope the explanation about how to use XPath for Web Scraping with Selenium is easy to understand and proves very useful. Do let us know in the comment section if there is anything specific you are looking for related to Python, Selenium or Web Scraping. We can come up with another blog on the requirement. On a separate note, in case you are wondering about which would be a better programming language between R and Python, we suggest you to visit another blog <a href=\"https:\/\/ivyproschool.com\/blog\/2020\/01\/09\/r-vs-python-for-data-science\/\">R vs Python<\/a> to get a better understanding between the two languages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Web scraping is a commonly used technology existing for a couple of decades now. We use programming languages like Python with libraries namely Beautiful Soup, Selenium, Scrapy, etc. or R with Rvest package for web scraping. Other web scraping tools are also available. A vivid explanation of how we do web scraping using Python is provided in the article named Web Scraping using Beautiful Soup.\u00a0 Further to the above, in this article, we are going to understand XPath and how it can be used to navigate through the HTML document for Web Scraping with Selenium to reach the target nodes using Python. Our Target Website &#8211; Let us consider the webpage of a very popular Indian daily English newspaper Telegraph https:\/\/www.telegraphindia.com\/ What Library are we using &#8211; We are using the robust Selenium web driver to navigate through the Telegraph website using XPath. What is XPath &#8211; The full form of XPath is XML Path language. It is a very popular Web Technology and W3C standard. We can access precise information in an XML\/HTML document using these concise and powerful XPath statements. Understanding the structure of XPath &#8211; First of all, let us see how can we find XPath of [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":9595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[851,5,881,715,552],"tags":[801,800,716,797,798,799],"class_list":["post-9581","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business-analytics","category-data-analytics","category-data-science","category-machine-learning-ai","category-technology","tag-attributes","tag-html","tag-python","tag-selenium","tag-selenium-web-driver","tag-xpath"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to use XPath for Web Scraping with Selenium? | Ivy Pro School<\/title>\n<meta name=\"description\" content=\"Here, We provide a detailed understanding of XPath and how to use it for Web Scraping with Selenium Webdriver. Learn and Grow With Ivy Pro School.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use XPath for Web Scraping with Selenium? | Ivy Pro School\" \/>\n<meta property=\"og:description\" content=\"Here, We provide a detailed understanding of XPath and how to use it for Web Scraping with Selenium Webdriver. Learn and Grow With Ivy Pro School.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/\" \/>\n<meta property=\"og:site_name\" content=\"R vs Python: Which Analytics Tool Should You Choose for Data Science?\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/ivyproschool\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-28T04:40:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-11T06:38:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"672\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ivy Professional School\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ivyproschool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ivy Professional School\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/\"},\"author\":{\"name\":\"Ivy Professional School\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\"},\"headline\":\"How to use XPath for Web Scraping with Selenium\",\"datePublished\":\"2020-02-28T04:40:22+00:00\",\"dateModified\":\"2021-06-11T06:38:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/\"},\"wordCount\":1534,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/How-to-use-xpath-with-selenium-final.png\",\"keywords\":[\"Attributes\",\"HTML\",\"python\",\"selenium\",\"selenium web driver\",\"XPath\"],\"articleSection\":[\"Business Analytics\",\"Data Analytics\",\"Data Science\",\"Machine Learning &amp; AI\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/\",\"name\":\"How to use XPath for Web Scraping with Selenium? | Ivy Pro School\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/How-to-use-xpath-with-selenium-final.png\",\"datePublished\":\"2020-02-28T04:40:22+00:00\",\"dateModified\":\"2021-06-11T06:38:21+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\"},\"description\":\"Here, We provide a detailed understanding of XPath and how to use it for Web Scraping with Selenium Webdriver. Learn and Grow With Ivy Pro School.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/How-to-use-xpath-with-selenium-final.png\",\"contentUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/How-to-use-xpath-with-selenium-final.png\",\"width\":1080,\"height\":672,\"caption\":\"How to use xpath with selenium\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/how-to-use-xpath-for-web-scraping-with-selenium\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use XPath for Web Scraping with Selenium\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\",\"name\":\"Ivy Professional School | Official Blog\",\"description\":\"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\",\"name\":\"Ivy Professional School\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"caption\":\"Ivy Professional School\"},\"sameAs\":[\"http:\\\/\\\/www.ivyproschool.com\",\"https:\\\/\\\/facebook.com\\\/ivyproschool\",\"https:\\\/\\\/instagram.com\\\/ivyproschool\",\"https:\\\/\\\/x.com\\\/ivyproschool\",\"https:\\\/\\\/youtube.com\\\/ivyproschool\"],\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/author\\\/prateek\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use XPath for Web Scraping with Selenium? | Ivy Pro School","description":"Here, We provide a detailed understanding of XPath and how to use it for Web Scraping with Selenium Webdriver. Learn and Grow With Ivy Pro School.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/","og_locale":"en_US","og_type":"article","og_title":"How to use XPath for Web Scraping with Selenium? | Ivy Pro School","og_description":"Here, We provide a detailed understanding of XPath and how to use it for Web Scraping with Selenium Webdriver. Learn and Grow With Ivy Pro School.","og_url":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/","og_site_name":"R vs Python: Which Analytics Tool Should You Choose for Data Science?","article_author":"https:\/\/facebook.com\/ivyproschool","article_published_time":"2020-02-28T04:40:22+00:00","article_modified_time":"2021-06-11T06:38:21+00:00","og_image":[{"width":1080,"height":672,"url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final.png","type":"image\/png"}],"author":"Ivy Professional School","twitter_card":"summary_large_image","twitter_creator":"@ivyproschool","twitter_misc":{"Written by":"Ivy Professional School","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#article","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/"},"author":{"name":"Ivy Professional School","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d"},"headline":"How to use XPath for Web Scraping with Selenium","datePublished":"2020-02-28T04:40:22+00:00","dateModified":"2021-06-11T06:38:21+00:00","mainEntityOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/"},"wordCount":1534,"commentCount":0,"image":{"@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final.png","keywords":["Attributes","HTML","python","selenium","selenium web driver","XPath"],"articleSection":["Business Analytics","Data Analytics","Data Science","Machine Learning &amp; AI","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/","url":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/","name":"How to use XPath for Web Scraping with Selenium? | Ivy Pro School","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#primaryimage"},"image":{"@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final.png","datePublished":"2020-02-28T04:40:22+00:00","dateModified":"2021-06-11T06:38:21+00:00","author":{"@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d"},"description":"Here, We provide a detailed understanding of XPath and how to use it for Web Scraping with Selenium Webdriver. Learn and Grow With Ivy Pro School.","breadcrumb":{"@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#primaryimage","url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final.png","contentUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/How-to-use-xpath-with-selenium-final.png","width":1080,"height":672,"caption":"How to use xpath with selenium"},{"@type":"BreadcrumbList","@id":"https:\/\/ivyproschool.com\/blog\/how-to-use-xpath-for-web-scraping-with-selenium\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ivyproschool.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to use XPath for Web Scraping with Selenium"}]},{"@type":"WebSite","@id":"https:\/\/ivyproschool.com\/blog\/#website","url":"https:\/\/ivyproschool.com\/blog\/","name":"Ivy Professional School | Official Blog","description":"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ivyproschool.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d","name":"Ivy Professional School","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","caption":"Ivy Professional School"},"sameAs":["http:\/\/www.ivyproschool.com","https:\/\/facebook.com\/ivyproschool","https:\/\/instagram.com\/ivyproschool","https:\/\/x.com\/ivyproschool","https:\/\/youtube.com\/ivyproschool"],"url":"https:\/\/ivyproschool.com\/blog\/author\/prateek\/"}]}},"_links":{"self":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9581"}],"version-history":[{"count":1,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9581\/revisions"}],"predecessor-version":[{"id":10578,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9581\/revisions\/10578"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media\/9595"}],"wp:attachment":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}