When we learn web scraping or web automation its very important to understand the concepts of "XPATHS" and using them to get most benefit.
Learning XPATH is really easy as well interesting.
Now I will tell you about the structure of XPATHS in rest of the Blogpost
This is a very easy example of XPATH. This XPATH will target all the Text inside the Anchor Tag inside all the Div elements inside a page.
Example 2:
The above line of code will target Div with id='main-section'. This will provide you 1 or less than 1 result as id is always unique. But the case would be different if want to target Class.
Example 3:
This is target all the div with Class = 'social-icons'.lo
If you too love python and want to scrape and automate the web using python, then I recommend you a few tools like Scrappy, Selenium and there are total 8 ways to locate or access an element using selenium.
You would be surprised to know that XPATHS Version 1 was created in 1999 and since then we have many version of xpaths and many more to come. But current browsers only support XPATHS Version 1.
Learning XPATH is really easy as well interesting.
Now I will tell you about the structure of XPATHS in rest of the Blogpost
Structure of XPATHS
There no need to go deep inside XPATHS if you primarily want to learn web scraping or web automation but remember these two points given below to make your life easier.
- Remember that a XPATH always start with two forward slash "//"
- After 2 Forward slash comes the element name such as "p", "div", etc.
Example of XPATH:
Here are 3 examples which will facilitate the learning of XPATH and will make the stuff as easy as a loaf of bread.
Example 1:
//div/a/text()
This is a very easy example of XPATH. This XPATH will target all the Text inside the Anchor Tag inside all the Div elements inside a page.
Example 2:
//div[@id='main-section']
The above line of code will target Div with id='main-section'. This will provide you 1 or less than 1 result as id is always unique. But the case would be different if want to target Class.
Example 3:
//div[@class='social-icons']
This is target all the div with Class = 'social-icons'.lo
If you too love python and want to scrape and automate the web using python, then I recommend you a few tools like Scrappy, Selenium and there are total 8 ways to locate or access an element using selenium.
Comments
Post a Comment