Install wechatsogou via pip
masterInstall or upgrade the wechatsogou package using pip to use the WeChat Official Account crawler interface based on Sogou WeChat search.
pip install wechatsogou --upgraderepository·master·Indexed 27 days ago
https://github.com/chyroc/wechatsogouA Python-based crawler interface for WeChat Official Accounts using Sogou WeChat search. The library provides the WechatSogouAPI class to search for Official Accounts and articles, retrieve account metadata via get_gzh_info, fetch recent article history, and obtain trending articles from the Sogou WeChat homepage.
Install or upgrade the wechatsogou package using pip to use the WeChat Official Account crawler interface based on Sogou WeChat search.
pip install wechatsogou --upgradeTo use the library, instantiate the WechatSogouAPI class. You can configure several parameters during initialization, including retry attempts for captcha errors, proxies, and timeouts. The API accepts all standard requests library arguments.
import wechatsogou
# Default initialization
ws_api = wechatsogou.WechatSogouAPI()
# Set retry attempts for captcha errors (default is 1)
ws_api = wechatsogou.WechatSogouAPI(captcha_break_time=3)
# Configure proxies (ensure at least one HTTPS proxy is available)
ws_api = wechatsogou.WechatSogouAPI(proxies={
"http": "127.0.0.1:8888",
"https": "127.0.0.1:8888",
})
# Set request timeout
ws_api = wechatsogou.WechatSogouAPI(timeout=0.1)Use search_article(keyword) to search for WeChat articles matching a keyword.
Returns a list of dictionaries. Each dictionary contains two main objects:
article object:
title: Article titleurl: Article linkimgs: List of article image URLsabstract: Article abstract/summarytime: Article publication timestamp (10-digit integer)gzh object:
profile_url: Link to the last 10 broadcast pages of the source accountheadimage: Profile picture URLwechat_name: Official Account nameisv: Whether the account is a verified service account (1 or 0)import wechatsogou
ws_api = wechatsogou.WechatSogouAPI()
articles = ws_api.search_article('南京航空航天大学')Use get_gzh_article_by_hot(index) to retrieve trending articles from the Sogou WeChat homepage. The index parameter should be a constant from WechatSogouConst.hot_index (e.g., food).
Returns a list of dictionaries. Each dictionary contains:
gzh object:
headimage: Official Account profile picturewechat_name: Official Account namearticle object:
url: Temporary article linktitle: Article titleabstract: Article abstracttime: Publication timestamp (10-digit integer)open_id: Open IDmain_img: Cover image URLfrom wechatsogou import WechatSogouAPI, WechatSogouConst
ws_api = WechatSogouAPI()
# Example using the 'food' category index
gzh_articles = ws_api.get_gzh_article_by_hot(WechatSogouConst.hot_index.food)Use get_gzh_article_by_history(name) to retrieve the recent article history of a specific Official Account.
Returns a dictionary containing:
gzh object:
wechat_name: Account namewechat_id: WeChat IDintroduction: Account introductionauthentication: Verification statusheadimage: Profile picture URLarticle list (each item contains):
send_id: Broadcast ID (note: not unique, multiple messages can share an ID)datetime: Broadcast timestamp (10-digit integer)type: Message type (usually '49' for images/text)main: Boolean-like integer (1 if it's the first message in a broadcast, 0 otherwise)title: Article titleabstract: Article abstractfileid: File IDcontent_url: Article linksource_url: 'Read More' linkcover: Cover image URLauthor: Author namecopyright_stat: Copyright status (e.g., original content indicator)import wechatsogou
ws_api = wechatsogou.WechatSogouAPI()
history = ws_api.get_gzh_article_by_history('南航青年志愿者')Use get_gzh_info(name) to retrieve detailed metadata for a specific WeChat Official Account (GZH) by its name.
Returns a dictionary with the following keys:
profile_url: Link to the last 10 broadcast pagesheadimage: Profile picture URLwechat_name: Official Account namewechat_id: WeChat IDpost_perm: Number of broadcasts in the last month (int)view_perm: Total views in the last month (int)qrcode: QR code URLintroduction: Account introduction/bioauthentication: Verification statusimport wechatsogou
ws_api = wechatsogou.WechatSogouAPI()
info = ws_api.get_gzh_info('南航青年志愿者')Use get_sugg(keyword) to retrieve a list of suggested search terms related to a keyword, similar to search autocomplete functionality.
Returns: A list of strings (keywords).
Use search_gzh(keyword) to search for WeChat Official Accounts matching a keyword.
Returns a list of dictionaries. Each dictionary contains:
profile_url: Link to the last 10 broadcast pagesheadimage: Profile picture URLwechat_name: Official Account namewechat_id: WeChat IDpost_perm: Number of broadcasts in the last month (int)view_perm: Total views in the last month (int)qrcode: QR code URLintroduction: Account introductionauthentication: Verification statusimport wechatsogou
ws_api = wechatsogou.WechatSogouAPI()
results = ws_api.search_gzh('南京航空航天大学')