Пример #1
0
 def setUp(self):
     self.films = list(Film.search("john malkovich"))
     self.example = self.films[0]
     
     #several directors, screenwriters, genres, countries
     self.soup = make_request("http://www.filmweb.pl/Matrix")
     
     #no descrition; duration less than hour
     self.soup2 = make_request("http://www.filmweb.pl/film/Sipur+Ahava-1990-352246")
Пример #2
0
    def search(cls, phrase, max_page=1):
        """
        Searches for object based on the title/name. Returns a list of
        Film/Person objects with matching 'title'/'name' attributes.

        max_page = indicates from how many pages of search results
                   data will be extracted
        """
        page = 1
        
        #final_results = []
        while page <= max_page:
            url = "http://www.filmweb.pl/search/{}?q={}&page={}".format(cls.__name__.lower(), phrase, page)

            soup = make_request(url)

            if cls.__name__ == "Film":
                results = soup.select("a.filmPreview__link")
            elif cls.__name__ == "Person":
                results = soup.select(".hit__desc a")
            else:
                results = []

            for res in results:
                obj = None
                name = res.text.strip()
                link = "http://www.filmweb.pl" + res["href"]
                
                if cls.__name__ == "Film":
                    year = int(res.next_sibling.next_sibling.text)
                    id_ = int(res.parent.parent.parent.parent["data-id"])
                    obj = cls(title=name, url=link, year=int(year), id_=int(id_))
                    
                elif cls.__name__ == "Person":
                    obj = cls(name=name, url=link)
                    
                yield obj
            
            page += 1
Пример #3
0
 def setUp(self):
     self.people = list(Person.search("john malkovich"))
     self.example = self.people[0]
     
     self.soup = make_request("http://www.filmweb.pl/person/John.Malkovich")