本文整理匯總了Python中imdb.parser.http.bsouplxml._bsoup.BeautifulSoup.findAll方法的典型用法代碼示例。如果您正苦於以下問題:Python BeautifulSoup.findAll方法的具體用法?Python BeautifulSoup.findAll怎麽用?Python BeautifulSoup.findAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類imdb.parser.http.bsouplxml._bsoup.BeautifulSoup
的用法示例。
在下文中一共展示了BeautifulSoup.findAll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: checkForUpdateWindows
# 需要導入模塊: from imdb.parser.http.bsouplxml._bsoup import BeautifulSoup [as 別名]
# 或者: from imdb.parser.http.bsouplxml._bsoup.BeautifulSoup import findAll [as 別名]
def checkForUpdateWindows(self):
try:
data = urllib2.urlopen(self.downloads, timeout = self.timeout).read()
except (IOError, URLError):
log.error('Failed to open %s.' % self.downloads)
return False
try:
html = BeautifulSoup(data)
results = html.findAll('a', attrs = {'href':re.compile('/downloads/')})
for link in results:
if 'windows' in str(link.parent).lower():
downloadUrl = 'http://github.com' + link.get('href').replace(' ', '%20')
break
if 'r' + str(version.windows) in downloadUrl:
return False
return downloadUrl
except AttributeError:
log.debug('Nothing found.')
return False
示例2: findViaAlternative
# 需要導入模塊: from imdb.parser.http.bsouplxml._bsoup import BeautifulSoup [as 別名]
# 或者: from imdb.parser.http.bsouplxml._bsoup.BeautifulSoup import findAll [as 別名]
def findViaAlternative(self, movie):
results = {'480p':[], '720p':[], '1080p':[]}
arguments = urlencode({
's':movie
})
url = "%s?%s" % (self.backupUrl, arguments)
log.info('Searching %s' % url)
try:
data = urllib2.urlopen(url, timeout = self.timeout).read()
except (IOError, URLError):
log.error('Failed to open %s.' % url)
return results
try:
tables = SoupStrainer('div')
html = BeautifulSoup(data, parseOnlyThese = tables)
resultTable = html.findAll('h2', text = re.compile(movie))
for h2 in resultTable:
if 'trailer' in h2.lower():
parent = h2.parent.parent.parent
trailerLinks = parent.findAll('a', text = re.compile('480p|720p|1080p'))
try:
for trailer in trailerLinks:
results[trailer].insert(0, trailer.parent['href'])
except:
pass
except AttributeError:
log.debug('No trailers found in via alternative.')
return results
示例3: getDetails
# 需要導入模塊: from imdb.parser.http.bsouplxml._bsoup import BeautifulSoup [as 別名]
# 或者: from imdb.parser.http.bsouplxml._bsoup.BeautifulSoup import findAll [as 別名]
def getDetails(self, id):
url = self.detailUrl + str(id)
log.info('Scanning %s.' % url)
try:
data = urllib2.urlopen(url, timeout = self.timeout).read()
except (IOError, URLError):
log.error('Failed to open %s.' % url)
return False
# Search for theater release
theaterDate = 0
try:
theaterLink = SoupStrainer('a', href = re.compile('/month_theaters.html\?'))
theater = BeautifulSoup(data, parseOnlyThese = theaterLink)
theaterDate = int(time.mktime(parse(theater.a.contents[0]).timetuple()))
except AttributeError:
log.debug('No Theater release info found.')
# Search for dvd release date
dvdDate = 0
try:
try:
dvdLink = SoupStrainer('a', href = re.compile('/month_video.html\?'))
dvd = BeautifulSoup(data, parseOnlyThese = dvdLink)
dvdDate = int(time.mktime(parse(dvd.a.contents[0]).timetuple()))
except:
pass
# Try left column
if not dvdDate:
dvdReleases = SoupStrainer('p', text = re.compile('Released'))
dvd = BeautifulSoup(data, parseOnlyThese = dvdReleases)
for date in dvd:
foundDate = int(time.mktime(parse(date.replace('Released', '')).timetuple()))
dvdDate = foundDate if foundDate > dvdDate else dvdDate
except AttributeError:
log.debug('No DVD release info found.')
# Does it have blu-ray release?
bluray = []
try:
bees = SoupStrainer('b')
soup = BeautifulSoup(data, parseOnlyThese = bees)
bluray = soup.findAll('b', text = re.compile('Blu-ray'))
except AttributeError:
log.info('No Bluray release info found.')
dates = {
'id': id,
'dvd': dvdDate,
'theater': theaterDate,
'bluray': len(bluray) > 0
}
log.debug('Found: %s' % dates)
return dates
示例4: urlencode
# 需要導入模塊: from imdb.parser.http.bsouplxml._bsoup import BeautifulSoup [as 別名]
# 或者: from imdb.parser.http.bsouplxml._bsoup.BeautifulSoup import findAll [as 別名]
arguments = urlencode({
's':movie
})
url = "%s?%s" % (self.backupUrl, arguments)
log.debug('Searching %s' % url)
try:
data = urllib2.urlopen(url, timeout = self.timeout).read()
except (IOError, URLError), e:
log.debug('Failed to open %s. %s' % (url, e))
return results
try:
tables = SoupStrainer('div')
html = BeautifulSoup(data, parseOnlyThese = tables)
resultTable = html.findAll('h2', text = re.compile(movie))
for h2 in resultTable:
if 'trailer' in h2.lower():
parent = h2.parent.parent.parent
trailerLinks = parent.findAll('a', text = re.compile('480p|720p|1080p'))
try:
for trailer in trailerLinks:
results[trailer].insert(0, trailer.parent['href'])
except:
pass
except AttributeError:
log.debug('No trailers found in via alternative.')