yatish27 / linkedin-scraper

Scrapes the public profile of the linkedin page
MIT License
553 stars 221 forks source link

picture.nil? NoMethodError: undefined method `value' for nil:NilClass #60

Closed washingon closed 9 years ago

washingon commented 9 years ago

some profiles have a problem with picture. puts profile.picture NoMethodError: undefined method `value' for nil:NilClass

cernyjakub commented 9 years ago

I experience the same problem.

Apparently

(@page.at(".profile-picture img").attributes["src"].value.strip if @page.at(".profile-picture img"))

in profile.rb fails. It looks like on some profiles the profile IMG tag is present, but it is missing the SRC attribute...

cernyjakub commented 9 years ago

I did some more digging. On one of the problematic profiles I found this (this is the content of @page.at(".profile-picture img"):

 #<Nokogiri::XML::Element:0x2ad9dcaf0088 name="img" attributes=[
#<Nokogiri::XML::Attr:0x2ad9dceb8648 name="lazyload" value="true">, 
#<Nokogiri::XML::Attr:0x2ad9dceb8634 name="class" value="image photo lazy-load">,
#<Nokogiri::XML::Attr:0x2ad9dceb8620 name="alt" value="XXXXsomeName">, 
#<Nokogiri::XML::Attr:0x2ad9dceb860c name="data-delayed-url"
value="https://media.licdn.com/mpr/mpr/shrinknp_200_200/p/2/005/00b/2eb/16f4a3e.jpg">, 
#<Nokogiri::XML::Attr:0x2ad9dceb85f8 name="width" value="200">, 
#<Nokogiri::XML::Attr:0x2ad9dceb85e4 name="height" value="200">]>

They lazy-load pictures, so we will have to search for src or data-delayed-url attribute.

yatish27 commented 9 years ago

Can someone send a PR?

cernyjakub commented 9 years ago

I am trying to create it. Unfortunately current HEAD does not work with my app, so I will have to first find out what's the problem. Probably renaming linkedin-scraper to linkedin_scraper broke something...

yatish27 commented 9 years ago

Ya, I recently renamed the files to follow Ruby conventions

cernyjakub commented 9 years ago

OK - just a side note: after your rename, I had to add explicit :require => 'linkedin_scraper' to my Gemfile. Apparently the name change killed bundler auto-loading..

The PR for this issue is ready.