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 baidu_index.utils import test_cookies
from baidu_index import config
from baidu_index 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.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distributions

baidux-0.1.0-py3.7.egg (21.3 kB view details)

Uploaded Source

baidux-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: baidux-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for baidux-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5edf3651fd9cc3e9dec5f034487614eff2d440a6f20a23162fba58388f4db395
MD5 bb41c04af880be6e74a8814e7da4360f
BLAKE2b-256 f3f2a16ab9ff853fbcbf16653fd4be2419f80f3b38ff778f5486521935a41a75

See more details on using hashes here.

File details

Details for the file baidux-0.1.0-py3.7.egg.

File metadata

  • Download URL: baidux-0.1.0-py3.7.egg
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for baidux-0.1.0-py3.7.egg
Algorithm Hash digest
SHA256 892e51ec431a150fd2c0809f004107741983d8dbd96198293ec6732f67b4cb4a
MD5 b321a72bd58f5371374374f8f1e8c96b
BLAKE2b-256 dbc2eaec060fb12a524cabd2b97c5667e81f2fe9284538e593c9cd4baba199e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: baidux-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for baidux-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffee1fc33be434f6371295b9fb546378e7b91f0dfed21f7b9825eb847b766933
MD5 2cd8598fec58ce97b52fd9e8010195c1
BLAKE2b-256 50188289dd67bf5092f266d893c33b8928d5097f1b6707d6a5084ce3a464cc7b

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