Go to the profile of  Paras Patidar
Paras Patidar
I am working on Machine Learning, Python and Django.
2 min read

XPathology in WebScraping

Single forward slash / looks forward one generation.Double forward slash // looks forward all future generation.Square brackets [] help narrow in one specific element

Slashes and Brackets :

1.Single forward slash /  looks forward one generation

2. Double forward slash //  looks forward all future generation

3. Square brackets [] help narrow in one specific element

If we want to direct to the div element within the HTML document whose id attribute is "uid", then we could write the XPath string '//div[@id="uid"]'. The first part of this string, //div, first looks at all div elements in the HTML document. Then, using the brackets, we specify that we want only the div element with a specific id attribute (in this case uid). To note, the phrase @id="uid" in the brackets would be read as "attribute idequals uid".

WildCard in XPathology

The number of elements selected with the XPath string xpath = "/html/body//*" is equal to the number of children of the body element,  whereas the number of elements selected with the XPath string xpath = "/html/body/*" is equal to the total number of descendants of the body element.

Content With Contains

XPath contains notation

contains(@attri-name,"string-expr")

So, let's move to our next article on Web Scraping..