Ruby post match returning Nil.. like its supposed too -


my while loop busted somehow.. error:

`block in scrape': undefined method `post_match' nil :nilclass   (nomethoderror) 

its returning nil supposed after going through string, , populates array supposed too, last time hits .post_match fails because nil.. supposed nil.. not sure do?? want populate array , exit loop once parent_pic_first nil.

parent_pic_first = /\"hires\":\"/.match(pic).post_match     while parent_pic_first != nil          parent_pic = uri.extract(parent_pic_first, ['http'])          pic_list = []          pic_list.push(parent_pic[0])          parent_pic_first = /\"hires\":\"/.match(parent_pic_first).post_match          end 

the error isn't fact parent_pic_first nil, problem /\"hires\":\"/.match(parent_pic_first) nil. you're attempting call method post_match on nil value. nil.post_match quite not going work.

you need add in checks prevent calling post_match on nil, this:

parent_pic_first = /\"hires\":\"/.match(pic).post_match  while parent_pic_first != nil   parent_pic = uri.extract(parent_pic_first, ['http'])   pic_list = []   pic_list.push(parent_pic[0])   regex_return = /\"hires\":\"/.match(parent_pic_first)   if regex_return.nil?     break   else           parent_pic_first = regex_return.post_match   end end 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -