Skip to main content

A library to extract data from Baidu SERP and output it as JSON objects

Project description

English | 中文

Baidu SERP API

A Python library to extract data from Baidu Search Engine Results Pages (SERP) and output it as JSON objects.

Installation

pip install baidu-serp-api

Usage

from baidu_serp_api import BaiduPc, BaiduMobile

pc_serp = BaiduPc()
results = pc_serp.search('keyword', date_range='20240501,20240531', pn='2', proxies={'http': 'http://your-proxy-server:port'})
print(results)

m_serp = BaiduMobile()
results = m_serp.search('keyword', date_range='day', pn='2', proxies={'http': 'http://your-proxy-server:port'})
print(results)

# Filter the specified content. The following returned results do not contain 'recommend', 'last_page', 'match_count'
results = m_serp.search('关键词', exclude=['recommend', 'last_page', 'match_count'])

Parameters

  • keyword: The search keyword.
  • date_range (optional): Search for results within the specified date range. the format should be a time range string like '20240501,20240531', representing searching results between May 1, 2024, and May 31, 2024.
  • pn (optional): Search for results on the specified page.
  • proxies (optional): Use proxies for searching.

Return Values

  • {'code': 500, 'msg': '网络请求错误'}: Network request exception.
  • {'code': 501, 'msg': '百度安全验证'}: Baidu security verification required.
  • {'code': 404, 'msg': '未找到相关结果'}: No relevant results found.
  • {'code': 403, 'msg': '疑似违禁词'}: Suspected prohibited word.
  • {'code': 200, 'msg': 'ok', 'data': {'results': [], 'recommend': [], last_page': True}}: Successful response.
    • results search results list.
    • recommend recommend keywords.
    • last_page indicates whether it's the last page.

Disclaimer

This project is intended for educational purposes only and must not be used for commercial purposes or for large-scale scraping of Baidu data. This project is licensed under the GPLv3 open-source license. If other projects utilize the content of this project, they must be open-sourced and acknowledge the source. Additionally, the author of this project shall not be held responsible for any legal risks resulting from misuse. Violators will bear the consequences at their own risk.

百度SERP API

一个用于从百度搜索结果页面(SERP)提取数据并将其输出为JSON对象的Python库。

安装

pip install baidu-serp-api

使用

from baidu_serp_api import BaiduPc, BaiduMobile

pc_serp = BaiduPc()
results = pc_serp.search('关键词', date_range='20240501,20240531', pn='2', proxies={'http': 'http://你的代理服务器:端口'})
print(results)

m_serp = BaiduMobile()
results = m_serp.search('关键词', date_range='20240501,20240531', pn='2', proxies={'http': 'http://你的代理服务器:端口'})
print(results)

# 过滤指定内容,以下返回的结果不含'recommend', 'last_page', 'match_count'
results = m_serp.search('关键词', exclude=['recommend', 'last_page', 'match_count'])

参数

  • keyword: 搜索关键词。
  • date_range (可选): 在指定日期范围内搜索结果。格式应为一个时间范围字符串,如 '20240501,20240531',表示搜索2024年5月1日至2024年5月31日之间的结果。
  • pn (可选): 搜索指定页码的结果。
  • proxies (可选): 使用代理进行搜索。

返回值

  • {'code': 500, 'msg': '网络请求错误'}: 网络请求失败需要重试。
  • {'code': 502, 'msg': '百度安全验证'}: 需要进行百度安全验证。
  • {'code': 404, 'msg': '未找到相关结果'}: 未找到相关结果。
  • {'code': 403, 'msg': '疑似违禁词'}: 疑似违禁词。
  • {'code': 200, 'msg': 'ok', 'data': {'results': [], 'last_page': True}}: 成功响应。
    • results 搜索结果列表。
    • recommend 推荐相关搜索词。
    • last_page 表示是否为最后一页。

免责声明

本项目仅供学习之用,不可用于商业目的或大规模爬取百度数据。本项目采用GPLv3开源许可,若涉及到其他项目使用本项目内容,需开源并注明来源。同时,本项目作者不对滥用行为可能导致的法律风险承担责任,违者自负后果。

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

baidu_serp_api-1.0.5.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

baidu_serp_api-1.0.5-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file baidu_serp_api-1.0.5.tar.gz.

File metadata

  • Download URL: baidu_serp_api-1.0.5.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.5

File hashes

Hashes for baidu_serp_api-1.0.5.tar.gz
Algorithm Hash digest
SHA256 41807d80f6b27aedcc74dde9f325b9483642a804bb75a074a17b4a6b98509e9d
MD5 592bef621aeb017e89a1f63ebc0968d4
BLAKE2b-256 b80bc9309d98a1bcce8be51d2d52f40afdcaa2b25bb44a8d25c025382458be7a

See more details on using hashes here.

File details

Details for the file baidu_serp_api-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for baidu_serp_api-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 94453922611b9153276b7534c1dc7cb5cff7aeb0e0dfeace4daa87fd47411f39
MD5 ea8ed19c3eeb0739d2947a88edf572ac
BLAKE2b-256 d84a20cf5ad7e902cb0e5d6ec710d1a25554f08ce403d510838ab882851e3008

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