Skip to main content

Baidu Python SDK for index and search

Project description

Baidux - Python SDK for index and search

Install

pip install baidux

Usage

打开百度首页,登录后,找到 www.baidu.com 此条 GET 请求,并复制此条请求 request headers 里的 cookies

使用样例如下:

from baidux.utils import test_cookies
from baidux import config
from baidux import BaiduIndex, ExtendedBaiduIndex

cookies = """这里放cookie"""

# 测试cookies是否配置正确
# True为配置成功,False为配置不成功
print(test_cookies(cookies))

keywords = [['英雄联盟'], ['冠军杯', '英雄联盟'], ['抑郁', '自杀', '明星']]

# 获取城市代码, 将代码传入area可以获取不同城市的指数, 不传则为全国
# 媒体指数不能分地区获取
print(config.PROVINCE_CODE)
print(config.CITY_CODE)

# 获取百度搜索指数(地区为山东)
baidu_index = BaiduIndex(
    keywords=keywords,
    start_date='2018-01-01',
    end_date='2019-01-01',
    cookies=cookies,
    area=901
)
for index in baidu_index.get_index():
    print(index)

# 获取百度媒体指数
news_index = ExtendedBaiduIndex(
    keywords=keywords,
    start_date='2018-01-01',
    end_date='2019-01-01',
    cookies=cookies,
    kind='news'
)
for index in news_index.get_index():
    print(index)

# 获取百度咨询指数
feed_index = ExtendedBaiduIndex(
    keywords=keywords,
    start_date='2018-01-01',
    end_date='2019-01-01',
    cookies=cookies,
    kind='feed'
)
for index in feed_index.get_index():
    print(index)

Result

百度搜索指数: {'keyword': ['抑郁', '自杀', '明星'], 'type': 'wise', 'date': '2018-06-10', 'index': '1835'}
百度媒体指数: {'keyword': ['抑郁', '自杀', '明星'], 'date': '2018-12-29', 'index': '0'}
百度咨询指数: {'keyword': ['抑郁', '自杀', '明星'], 'date': '2018-12-29', 'index': '1102911'}

Tips

  • 不限制传入关键词的数量
  • 搜索指数最早的数据日期为2011-01-01
  • 开始时间超过最早的数据日期会导致数据不准确
  • 初始化类时传入area可以查询指定区域的百度指数, 默认为全国
  • 有些代码不是特别严谨, 有需要请自己DIY
  • 媒体指数不支持细分地域查询
  • 当查询百度指数未收录的关键词时也会出现报错,这个之后会修复

Changelog

2018/02/10 更新格式化数据的方法format_data
2018/12/29 更新查询指定区域百度指数的功能
2018/11/07 更新
2019/05/31 更新
2020/02/14 添加咨询指数和媒体指数的功能
2020/04/16 重构项目结构
2020/05/08 百度指数修改传递参数
2020/07/13 添加组合词查询

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

baidux-0.1.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

baidux-0.1.2-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file baidux-0.1.2.tar.gz.

File metadata

  • Download URL: baidux-0.1.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for baidux-0.1.2.tar.gz
Algorithm Hash digest
SHA256 78be5b111f344566464588405833041bc84eb0e9d75a53d168a6bbb6bc05bdf5
MD5 c525ea1a2c44e91eab2dd570cddd159f
BLAKE2b-256 062cb936e90c00e47602d6915bd39e289e44b1638b52f7ea1ef2a43f2af8f563

See more details on using hashes here.

File details

Details for the file baidux-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: baidux-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for baidux-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c140d55190edad3f3683c4e12aa484166ec714f63e69bb2e0d2db807ba22525
MD5 4341598bdad5cb2d7875d7e28b5927e1
BLAKE2b-256 f7e5e5248d259b7b33c9997f90a9bf847fae42c272cbebfa3b2e00fc97bfe34b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page