colonelpanic8 / okcupyd

A Library that enables programmatic interaction with okcupid.com, using okcupid.com's private okcupid JSON API and html scraping when necessary.
MIT License
110 stars 18 forks source link

Search returns IndexError #87

Open bearsoup opened 7 years ago

bearsoup commented 7 years ago

Thanks for making this available and for your continued work to get okcupyd functioning again. I should note before I continue that I'm not super well-versed in Python, but I do have a working knowledge of it. So thanks for your help and patience.

I've been working with some of the basic examples, but some things seemed to have stopped working in the past week or so. I noticed that as of recently searches return IndexError: list index out of range.

In [1]: import okcupyd

In [2]: session = okcupyd.Session.login()
u 
In [3]: u = okcupyd.User(session)

In [4]: profiles = u.search(location='San Jose, CA')
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/usr/local/lib/python2.7/site-packages/okcupyd/tasks/__init__.pyc in <module>()
----> 1 profiles = u.search(location='San Jose, CA')

/usr/local/lib/python2.7/site-packages/okcupyd/user.pyc in search(self, **kwargs)
    150                        available.
    151         """
--> 152         kwargs.setdefault('gender', self.profile.gender[0])
    153         gentation = helpers.get_default_gentation(self.profile.gender,
    154                                                   self.profile.orientation)

/usr/local/lib/python2.7/site-packages/okcupyd/util/__init__.pyc in __get__(self, obj, cls)
     48         if obj is None:
     49             return self
---> 50         value = self.func(obj)
     51         setattr(obj, self.func.__name__, value)
     52         return value

/usr/local/lib/python2.7/site-packages/okcupyd/profile.pyc in gender(self)
    273     def gender(self):
    274         """The gender of the user associated with this profile."""
--> 275         return xpb.span.with_class('ajax_gender').get_text_(self.profile_tree)
    276 
    277     @util.cached_property

/usr/local/lib/python2.7/site-packages/okcupyd/xpath.pyc in get_text_(self, tree)
     76 
     77     def get_text_(self, tree):
---> 78         return self.apply_(tree)[0].text_content()
     79 
     80     def __repr__(self):

IndexError: list index out of range

I tried this a little over a week ago and it seemed to be working. Here are the results from last time I saw it working correctly:

profiles = u.search(location='95064', gentation='everybody', looking_for='casual
    ...:  sex')

In [53]: for profile in profiles[:3]:
    ...:     for photo_info in profile.photo_infos:
    ...:         print(photo_info.jpg_uri)
    ...:         
https://k0.okccdn.com/php/load_okc_image.php/images/6042441585283578132.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/7296983650060597387.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/15937235682687438391.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/6634255176753093252.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/14812250870738753533.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/5751529778072505961.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/3504142129961180037.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/5583417192368636057.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/9128104112864859652.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/7498761296118706495.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/1808164023788341298.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/849251583688822717.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/9185313602729909017.jpg
https://k0.okccdn.com/php/load_okc_image.php/images/16203954055593003086.jpg

Thanks for your help any any insight you can offer.

colonelpanic8 commented 7 years ago

It looks like they probably updated the position of the gender in the website.

It recently occured to me that okcupid MUST have a private api that they use for their mobile apps, so I think I'm going to try to migrate that when trying to get some of these details.

CrazySyntax commented 7 years ago

I also encountered this issue.

michaelmyc commented 7 years ago

When would the update be available? I am encountering this issue and is desperate to try to solve it.

colonelpanic8 commented 7 years ago

@tydlwav I honestly don't have plans to fix it myself, but I would welcome pull requests.

If you just want to try to get something working. You might want to try removing the gender[0] line. I suspect that search might still work.

michaelmyc commented 7 years ago

I'll see if I can find a way to get it to work. Thanks, though.