wechatsogou Documentation

repository·master·Indexed 27 days ago

https://github.com/chyroc/wechatsogou

A 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.

Tokens
1.6K
Snippets
7
Records
10
Agent score
42%

What's inside wechatsogou

  1. Initialize the WechatSogouAPI

    master

    To 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)
  2. Troubleshoot missing article URLs or expired links

    master
    If you receive an error indicating that the link has expired or you cannot obtain the original article URL, it is because WeChat is blocking this specific interface. You must save the article content within the temporary link's validity period.
  3. Search WeChat articles with search_article

    master

    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 title
    • url: Article link
    • imgs: List of article image URLs
    • abstract: Article abstract/summary
    • time: Article publication timestamp (10-digit integer)

    gzh object:

    • profile_url: Link to the last 10 broadcast pages of the source account
    • headimage: Profile picture URL
    • wechat_name: Official Account name
    • isv: Whether the account is a verified service account (1 or 0)
    import wechatsogou
    
    ws_api = wechatsogou.WechatSogouAPI()
    articles = ws_api.search_article('南京航空航天大学')
  4. Get trending articles with get_gzh_article_by_hot

    master

    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 picture
    • wechat_name: Official Account name

    article object:

    • url: Temporary article link
    • title: Article title
    • abstract: Article abstract
    • time: Publication timestamp (10-digit integer)
    • open_id: Open ID
    • main_img: Cover image URL
    from 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)
  5. Parse recent articles from an account with get_gzh_article_by_history

    master

    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 name
    • wechat_id: WeChat ID
    • introduction: Account introduction
    • authentication: Verification status
    • headimage: Profile picture URL

    article 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 title
    • abstract: Article abstract
    • fileid: File ID
    • content_url: Article link
    • source_url: 'Read More' link
    • cover: Cover image URL
    • author: Author name
    • copyright_stat: Copyright status (e.g., original content indicator)
    import wechatsogou
    
    ws_api = wechatsogou.WechatSogouAPI()
    history = ws_api.get_gzh_article_by_history('南航青年志愿者')
  6. Get specific Official Account information with get_gzh_info

    master

    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 pages
    • headimage: Profile picture URL
    • wechat_name: Official Account name
    • wechat_id: WeChat ID
    • post_perm: Number of broadcasts in the last month (int)
    • view_perm: Total views in the last month (int)
    • qrcode: QR code URL
    • introduction: Account introduction/bio
    • authentication: Verification status
    import wechatsogou
    
    ws_api = wechatsogou.WechatSogouAPI()
    info = ws_api.get_gzh_info('南航青年志愿者')
  7. Search for Official Accounts with search_gzh

    master

    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 pages
    • headimage: Profile picture URL
    • wechat_name: Official Account name
    • wechat_id: WeChat ID
    • post_perm: Number of broadcasts in the last month (int)
    • view_perm: Total views in the last month (int)
    • qrcode: QR code URL
    • introduction: Account introduction
    • authentication: Verification status
    import wechatsogou
    
    ws_api = wechatsogou.WechatSogouAPI()
    results = ws_api.search_gzh('南京航空航天大学')