1

im trying to get all link text from a tag p and with a specific class. Then create a loop to find all other similar elements.

how it looks

so far i am using this : the value i want is in

    <div class='some other class'>
     <p class='machine-name install-info-entry x-hidden-focus'> text i want 
     </p> ==$0

    installations = browser.find_elements_by_css_selector('p.machine-name.install-info-entry.x-hidden-focus')

any help is appreciated. thanks.

2
  • what do you mean by "link text from a <p> tag"? Commented Aug 3, 2018 at 16:48
  • the text i want is after the tag <p and after the second class ' machine-name....'> text i want. Commented Aug 3, 2018 at 17:07

1 Answer 1

1

You can just use .text

installations = browser.find_elements_by_css_selector('p.machine-name.install-info-entry.x-hidden-focus') 

for installation in installations: 
  print(installation.text)  

Note that installations is a list of web elements, whereas installation is just a web element from the list.

UPDATE1:

If you want to extract the attribute from a web element, then you can follow this code:

print(installation.get_attribute("attribute name"))  

You should pass your desired attribute name in get_attribute method.

You can read innerHTML attribute to get source of the content of the element or outerHTML for source with the current element.

installation.get_attribute('innerHTML')

Hope this will be helpful.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the answer, i gave this a try and no errors but the file is not generated and if i create it, nothing is written to it.
Which file you are talking about ?
oh my bad its not a file, its the attribute from installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.