0

Im scraping a web using Goutte/Symfony2 and i have a problem with a filter,

i have in $msg the crawler (part of the web), if i print the html i can see inside of $msg a div with class .mola, why if i filter $msg to get the text from .mola i get The current node list is empty ?

$msg = '<div class="mola_wrap"> 
            <span class="mola" title="titleinside">109</span>'; // in $msg are more code

$msg->filter('.mola')->text();

Thank you!!

1 Answer 1

1

Assuming that $msg is a Crawler object which contains this html

<div class="mola_wrap"> 
    <span class="mola" title="titleinside">109</span>
</div>

your code is just fine, maybe the website you are crawling does not have .mola class in some pages

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

6 Comments

$posts[$i]['likes'] = trim($msg->filter('.mola')->first()->text()); get the same, node is empty
could you please post some more html code so i can see the problem because the code above works
gist.github.com/kaseOga/92d68e7f3216a2f50e32 here is all the html (i get these doing an echo $msg->html();)
can you try doing $mola = new Crawler($msg->html()); and then call $mola->filter('.mola')->text();
I'm VERY retard cause i had the same problem with other filter before this with same $msg and the problem is $msg is a Crawler of a bucle, some post can have span.mola and other post can't have... the solution is simple adding a if counting if exist o no :P sorry and thanks!!
|

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.