从tvbythenumbers.zap2it.com访问收视率的python scraper

py-zap的Python项目详细描述


py_zap是一个python scraper,用于从tvbythenumbers.zap2it.com获取每日广播和有线电视收视率。

安装

使用pip安装:

>>> pip install py_zap

或者克隆此存储库并运行:

>>> python setup.py install

广播收视率

我们来取final broadcast ratings for October 27, 2016.

  • 如果不包含日期参数,则默认为昨天的日期
>>> from py_zap import Broadcast
>>> ratings = Broadcast('October 27, 2016')
  • 现在我们可以查看图表条目:
>>> entry = ratings[0]     # Gives the 1st entry
>>> entry.show             # Get the name of the show
'The Big Bang Theory'
>>> entry.viewers          # Get the number of viewers (in millions)
14.3
>>> entry.rating           # Get the rating (percentage)
3.4
  • 我们还可以print通过:
>>> print(ratings)
>>>
Final Broadcast Ratings for Thursday, October 27 2016
|Show                          |Time      |Network|Viewers|Rating |Share  |
+-------------------------------------------------------------------------+
|The Big Bang Theory           |    8 p.m.|    CBS|   14.3|    3.4|   13.0|
|Grey’s Anatomy                |    8 p.m.|    ABC|    8.2|    2.2|    8.0|
|Superstore                    |    8 p.m.|    NBC|    4.2|    1.3|    5.0|
|Rosewood                      |    8 p.m.|    FOX|    3.4|    0.8|    3.0|
|Legends of Tomorrow           |    8 p.m.| The CW|    1.8|    0.6|    2.0|
|The Great Indoors             | 8:30 p.m.|    CBS|    8.8|    1.9|    7.0|
|The Good Place                | 8:30 p.m.|    NBC|    3.9|    1.2|    4.0|
|Mom                           |    9 p.m.|    CBS|    7.0|    1.5|    5.0|
|Chicago Med                   |    9 p.m.|    NBC|    7.1|    1.5|    5.0|
|Notorious                     |    9 p.m.|    ABC|    3.8|    0.8|    3.0|
|Pitch                         |    9 p.m.|    FOX|    2.9|    0.8|    3.0|
|Supernatural                  |    9 p.m.| The CW|    1.7|    0.6|    2.0|
|Life in Pieces                | 9:30 p.m.|    CBS|    6.0|    1.4|    5.0|
|Pure Genius                   |   10 p.m.|    CBS|    6.2|    1.0|    4.0|
|The Blacklist                 |   10 p.m.|    NBC|    5.5|    1.2|    4.0|
|How to Get Away with Murder   |   10 p.m.|    ABC|    4.1|    1.2|    4.0|

默认情况下,将获取最终广播收视率。若要访问先前发布但不太准确的快速分级,请将“final”参数设置为false。如果没有可用的最终评级,它将重定向到快速访问评级。

>>> ratings = Broadcast('October 27, 2016', final=False)

电缆额定值

获取cable ratings for October 27, 2016:

>>> from py_zap import Cable
>>> ratings = Cable('October 27, 2016')

其他可以做的事情

排序图结果

  • 广播或有线电视的收视率可以根据shownettimeratingviewers
  • 进行排序。
  • 广播收视率只能在share上排序
>>> ratings = Cable('October 27, 2016').sort('viewers')    # Sort cable ratings by viewers
>>> ratings = Broadcast('October 27, 2016').sort('share')  # Sort broadcast ratings by share (broadcast only)

获取特定节目或网络

  • 如果要获取多个列表,请传递列表
>>> ratings = Broadcast('October 27, 2016', show='Supernatural')     # Fetch a specific show
>>> ratings = Broadcast('October 27, 2016', network=['CBS', 'NBC'])  # Fetch a specific network

遍历多周

>>> next_week = ratings.get_next_week()  # Get next week's date
>>> last_week = ratings.get_last_week()  # Get last week's date

get network average(仅限广播)

>>> averages = ratings.get_averages()  # Get the ratings/viewers averages for broadcast networks
>>> averages['NBC']
{'rating': 1.3, 'viewers': 5.56, 'share': 5.0}

许可证

  • 这个项目是在麻省理工学院的许可下进行的。
  • 所有内容归论坛媒体公司所有。有关更多详细信息,请参见zap2it.com的Terms of Service

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring AOP:在方法之间交换信息   数组Java将字符串转换为字符[]   堆内存java。lang.OutOfMemoryError:PermGen space+java   安卓 Java。lang.ClassCastException:无法将活动强制转换到接口   java尝试使用气泡排序将随机整数数组从最大到最小排序   线程“main”java中的indexoutofboundsexception异常。lang.ArrayIndexOutofBounds异常:发电机处为3。main(Generator.java:35)   java“宽大”有什么用?   java SimpleCaptcha NoSuchMethodError   java在哪里部署Web服务的jar依赖项?   Java8获取列表中连续数字的函数方法   java为什么JWT令牌不安全?   java Uber API:在请求或发出令牌时指定多个作用域会返回无效的请求参数   java如何使用映射器从包含多个引用单元的JSON字符串中获取对象列表?   java警告匿名子类(?)没有串行版本   Jackson 2.9.0中的java JsonGenerationException。pr1   java试图打印多个catch语句   java如何创建一个sql表并获得每个唯一字段的平均价格?   java为什么SetMinimumSize设置最小高度而不是宽度?   java与使用POI合并的混淆   java在Xpath中使用“AND”和“normalizespace”时在不同浏览器中遇到不同的错误