Issue
I'm pulling contact information (text) from a website and I can currently pull all the class data, using the following XPath syntax:
//*[@id="nomapdata"]/div/div/div/div[2]/div[1]
Using this XPath expression for the element, I get the following text as the result:
Name
Title
Company Website
Phone Number
I want to pull each of these elements individually, but the problem is that, the data is separated by <br> </br>
, and I haven't had success on isolating each element.
Below is an example of the HTML structure:
<div class="col-sm-d">
"
Name"
<br>
"
Title"
<br>
a href="www.website.com" target="_blank">http://www.website.com</a>
<br>
"
Phone: (555) 555-5555"
<br>
The only element I am able to isolate is the website.
How can I isolate each data in this scenario?
Solution
Try to get the list of text nodes as
driver.find_element_by_xpath('//*[@id="nomapdata"]/div/div/div/div[2]/div[1]').text.split("\n")
If there are more text nodes after the phone number which you don't want to use:
driver.find_element_by_xpath('//*[@id="nomapdata"]/div/div/div/div[2]/div[1]').text.split("\n")[:4]
Answered By - Andersson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.