GithubHelp home page GithubHelp logo

_scrapLiVideos() in getVideos() raise AttributeError, line 80 soup_data.find("div", class_="sectionWrapper") returns None about pornhub-api HOT 7 OPEN

sskender avatar sskender commented on June 8, 2024
_scrapLiVideos() in getVideos() raise AttributeError, line 80 soup_data.find("div", class_="sectionWrapper") returns None

from pornhub-api.

Comments (7)

AcGW-RErCotWd avatar AcGW-RErCotWd commented on June 8, 2024

Traceback (most recent call last):
File "***site-packages\pornhub\videos.py", line 247, in getVideos
for possible_video in self._scrapLiVideos(self._loadPage(page_num=page, sort_by=sort_by)):
File "***site-packages\pornhub\videos.py", line 80, in scrapLiVideos
return soup_data.find("div", class
="sectionWrapper").find_all("li", { "class" : re.compile(".videoblock videoBox.") } )
AttributeError: 'NoneType' object has no attribute 'find_all'

from pornhub-api.

AcGW-RErCotWd avatar AcGW-RErCotWd commented on June 8, 2024

I believe there is an error happening in the _loadPage() method, where the page loaded was actually the home page instead of the search page wanted (thus making the _scrapLiVideos() to malfunction). This is pretty weird, lol

from pornhub-api.

AcGW-RErCotWd avatar AcGW-RErCotWd commented on June 8, 2024

Okay, there is a 404 request error in line 66 of _loadPage(), that is probably the cause of trouble

And the reason why such trouble occurs is because I input a keyword string where punctuations exists.

from pornhub-api.

AcGW-RErCotWd avatar AcGW-RErCotWd commented on June 8, 2024

But the error continues, the _scrapLiVideos(self, soup_data) returns an empty list that causes an infinite loop

The find('sectionWrapper') method seems to return the 'sectionWrapper PremiumSuggestion' node, which is not wanted

from pornhub-api.

SashaSZ avatar SashaSZ commented on June 8, 2024

Okay, there is a 404 request error in line 66 of _loadPage(), that is probably the cause of trouble

And the reason why such trouble occurs is because I input a keyword string where punctuations exists.

ok i'll add code that removes any punctuation:

for item in self.keywords:
    item = re.sub(r"[^\w\s]", "", item).replace("_", " ")

That seems to work

from pornhub-api.

AcGW-RErCotWd avatar AcGW-RErCotWd commented on June 8, 2024

Cool, I also found a way to correct the infinite loop error caused by not finding the wanted "sectionWrapper"
I rewrite and change the method _scrapLiVideos() a bit, and so far it seems to work.

    def _scrapLiVideos(self, soup_data) -> list:
        section_wrappers = soup_data.findAll("div", class_="sectionWrapper")
        for wrapper in section_wrappers:
            LiVideos = wrapper.find_all("li", {"class": re.compile(".*videoblock videoBox.*")})
            if LiVideos != []:
                return LiVideos
        raise Exception('LiVideos Not Found')

from pornhub-api.

SashaSZ avatar SashaSZ commented on June 8, 2024

Cool, I also found a way to correct the infinite loop error caused by not finding the wanted "sectionWrapper" I rewrite and change the method _scrapLiVideos() a bit, and so far it seems to work.

    def _scrapLiVideos(self, soup_data) -> list:
        section_wrappers = soup_data.findAll("div", class_="sectionWrapper")
        for wrapper in section_wrappers:
            LiVideos = wrapper.find_all("li", {"class": re.compile(".*videoblock videoBox.*")})
            if LiVideos != []:
                return LiVideos
        raise Exception('LiVideos Not Found')

Nice, also I added something similar for future gifs just in case. Nothing seems to be broken :D

from pornhub-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.