本文整理汇总了Python中pattern.web.DOM.get_elements_by_classname方法的典型用法代码示例。如果您正苦于以下问题:Python DOM.get_elements_by_classname方法的具体用法?Python DOM.get_elements_by_classname怎么用?Python DOM.get_elements_by_classname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pattern.web.DOM
的用法示例。
在下文中一共展示了DOM.get_elements_by_classname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape_top_250
# 需要导入模块: from pattern.web import DOM [as 别名]
# 或者: from pattern.web.DOM import get_elements_by_classname [as 别名]
def scrape_top_250(url):
"""
Scrape the IMDB top 250 movies index page.
Args:
url: pattern.web.URL instance pointing to the top 250 index page
Returns:
A list of strings, where each string is the URL to a movie's page on
IMDB, note that these URLS must be absolute (i.e. include the http
part, the domain part and the path part).
"""
movie_urls = []
dom = DOM(url.download(cached=True))
allurls = dom.get_elements_by_classname("titleColumn")
for oneurl in allurls:
link = abs(oneurl[1].attrs.get("href", ""), base=url.redirect or url.string)
movie_urls.append(link)
# return the list of URLs of each movie's page on IMDB
return movie_urls