Перейти к навигации

Use Python to research camping-equipment questions in Kuaishou comments

To find what people still need explained about camping equipment, save one Kuaishou search with the Python script ks_read.py (kuaishou.app.search_video_v2), select the posts that show real use, then save each selected post’s first comment page with the same script (kuaishou.app.fetch_video_comment) and read the carrying, storage and power questions. The handoff is a sheet of “question—excerpt—conditions—source—next step” rows for product or editorial follow-up.

If you already have verified post IDs, skip the search and start with comments. If you already saved responses, reuse the saved files before making new requests.

1. Plan the initial round

ks_read.py uses only the Python 3 standard library. Set BEATAPI_API_KEY in your local environment. Each run of ks_read.py makes one request and does not write the authentication header to disk.

The first round is one search plus the first comment page of each of three selected posts: four requests at most. Estimate the cost with current pricing.

2. Save a request and response

Save the script below as ks_read.py. In search mode the script calls kuaishou.app.search_video_v2; in comments mode the script calls kuaishou.app.fetch_video_comment. Both modes send an empty pcursor for the first page.

import json
import os
import sys
from datetime import datetime, timezone
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
if len(sys.argv) != 4 or sys.argv[1] not in {"search", "comments"}:
raise SystemExit("Usage: python3 ks_read.py search|comments VALUE NEW_DIRECTORY")
mode, value, directory = sys.argv[1:]
if not value.strip():
raise SystemExit("Supply a keyword or a verified photo ID")
key = os.environ.get("BEATAPI_API_KEY")
if not key:
raise SystemExit("Set BEATAPI_API_KEY in your local environment")
if mode == "search":
action = "kuaishou.app.search_video_v2"
params = {"keyword": value, "pcursor": ""}
else:
action = "kuaishou.app.fetch_video_comment"
params = {"photo_id": value, "pcursor": ""}
body = {"action": action, "params": params}
out = Path(directory)
out.mkdir(parents=True, exist_ok=False)
(out / "request.json").write_text(json.dumps(body, ensure_ascii=False, indent=2), encoding="utf-8")
started = datetime.now(timezone.utc).isoformat()
(out / "attempt.json").write_text(json.dumps({"started_at": started, "action": action}), encoding="utf-8")
request = Request("https://api.beatapi.io/v1/social-data/call",
data=json.dumps(body).encode("utf-8"), method="POST",
headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"})
try:
with urlopen(request, timeout=60) as response:
status, raw = response.status, response.read()
except HTTPError as error:
status, raw = error.code, error.read()
except URLError:
(out / "transport-error.json").write_text(json.dumps({"outcome": "unknown", "action": action}), encoding="utf-8")
raise SystemExit("No final response saved; review the attempted request before repeating")
(out / "response.json").write_bytes(raw)
(out / "call.json").write_text(json.dumps({"action": action, "params": params,
"http_status": status, "started_at": started,
"finished_at": datetime.now(timezone.utc).isoformat(),
"response_file": "response.json", "platform_review": "required"},
ensure_ascii=False, indent=2), encoding="utf-8")
try:
payload = json.loads(raw)
except (ValueError, UnicodeError):
raise SystemExit("Saved a non-JSON response; inspect response.json")
if status != 200 or not isinstance(payload, dict) or payload.get("status") != "succeeded" or payload.get("error") is not None or payload.get("action") != action:
raise SystemExit("Saved a failed or unexpected response; inspect response.json")
print("Saved response for platform-content review: " + str(out / "response.json"))

Retrieve the first search batch:

python3 ks_read.py search 'camping equipment' ks-search-01

The new directory holds request.json (inputs), attempt.json (attempt time), call.json (call record) and response.json (original response). ks_read.py checks the public execution envelope (status, error, action) and marks platform_review as required, because you still need to read the platform content. Every HTTP response is saved. When the network drops before a final response, the script writes transport-error.json and does not resend; review the attempted request before you run the command again.

3. Select for the research question

  1. Confirm each returned post and the post’s creator in ks-search-01/response.json.
  2. Prefer posts with outdoor situations, demonstrations and specific experience. Record an exclusion reason for slogans, namesakes and unrelated product displays.
  3. For each selected post, keep the original identifiers, the source, the selection reason and the collection time.
  4. Match the post to the question: carrying research needs storage and movement situations; power research needs the actual equipment and conditions. Do not treat every item as the same product.
  5. Record whether you read the video, the images or only the text; see post formats.

kuaishou.app.search_video_v2 accepts only a keyword and a cursor. To filter by publication period, duration or likes ordering, use the comprehensive filters instead.

4. Read selected comments

Pass the verified post ID and a new directory name:

python3 ks_read.py comments '<confirmed_photo_id>' ks-comments-01

Check that the comments discuss the same equipment as the post. “Does this fit in a backpack?” is a carrying question; a claim of overnight use needs the equipment, the load and the environment. Record the conditions the commenter states separately from the details still missing.

When a selected comment has an author explanation or correction in the reply thread, read the replies as described in comment context, and keep the post ID and root_comment_id. ks_read.py reads only the first comment page; the script does not fetch later pages or expand reply threads.

5. Hand off useful questions

For each question, keep the topic, excerpts, post and comment sources, parent relationships, conditions, existing answers, open items and next step. Find duplicates by comment ID, and count supporting comments separately from distinct posts.

For example, send a storage-size question to specification review. When the author already answered a question, add the author’s answer next to the question. Read a “same question” reply together with the reply’s parent comment. Attach the excerpts to each theme instead of reducing the discussion to sentiment labels.

Export the question sheet as a UTF-8 CSV with one open question per row. The fictional row below points to a saved response and to row C01 in the comment sheet.

question,comment_excerpt,source,details_to_check,next_step
Will it fit in a backpack?,Does this fit in a backpack?,ks-comments-01/response.json · C01,Backpack interior and packed device dimensions,Check the specs and add a photo of the packed device

Share the comment sheet with the CSV so teammates can follow C01 back to the excerpt, post and comment ID.

For the assistant:

Reuse these Kuaishou search and comment originals, selecting actual camping situations. Organize carrying, storage and power questions with wording and conditions. Identify reply context still needed and attach sources, answerable material and open questions, stating this round’s scope.

Act on the questions the saved comments already support before you fetch more material. ks_read.py runs once per command; set up recurring runs, storage and notifications in your own task environment.