0

I have the following HTML code:

<div class="sites-split">
    <ul>
        <li><a href="http://www.page1.com/" target="_blank">text 1</a></li>
        <li><a href="http://www.page2.com/" target="_blank">text 2</a></li>
    </ul>
    <ul>
        <li><a href="http://www.page3.com/" target="_blank">text 3</a></li>
        <li><a href="http://www.page4.com/" target="_blank">text 4</a></li>
    </ul>
</div>

I want to extract te links and the text associated to that link, I manage to get the links by doing:

response.css("div.sites-split a::attr(href)").getall()

But I don't know how to get the text, I tried:

response.css("div.sites-split a::attr(target)").getall()

But all I get is:

['_blank',
 '_blank',
 '_blank',
 '_blank']

1 Answer 1

4

You're extracting another attribute, but you need text. Try response.css("div.sites-split a::text").getall()

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

Comments

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.