{"record":{"id":"2e4bfa1203501755","repo":"soimort/you-get","slug":"url-does-not-conform-to-specifications-support-co","errorCode":null,"errorMessage":"URL does not conform to specifications, Support column and question only.Example URL: https://zhuanlan.zhihu.com/p/51669862 or https://www.zhihu.com/question/267782048/answer/490720324","messagePattern":"URL does not conform to specifications, Support column and question only\\.Example URL: https://zhuanlan\\.zhihu\\.com/p/51669862 or https://www\\.zhihu\\.com/question/267782048/answer/490720324","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/you_get/extractors/zhihu.py","lineNumber":13,"sourceCode":"#!/usr/bin/env python\n\n__all__ = ['zhihu_download', 'zhihu_download_playlist']\n\nfrom ..common import *\nimport json\n\n\ndef zhihu_download(url, output_dir='.', merge=True, info_only=False, **kwargs):\n    paths = url.split(\"/\")\n    # question or column\n    if len(paths) < 3 and len(paths) < 6:\n        raise TypeError(\"URL does not conform to specifications, Support column and question only.\"\n                        \"Example URL: https://zhuanlan.zhihu.com/p/51669862 or \"\n                        \"https://www.zhihu.com/question/267782048/answer/490720324\")\n\n    if (\"question\" not in paths or \"answer\" not in paths) and \"zhuanlan.zhihu.com\" not in paths:\n        raise TypeError(\"URL does not conform to specifications, Support column and question only.\"\n                        \"Example URL: https://zhuanlan.zhihu.com/p/51669862 or \"\n                        \"https://www.zhihu.com/question/267782048/answer/490720324\")\n\n    html = get_html(url, faker=True)\n    title = match1(html, r'data-react-helmet=\"true\">(.*?)</title>')\n    for index, video_id in enumerate(matchall(html, [r'<a class=\"video-box\" href=\"\\S+video/(\\d+)\"'])):\n        try:\n            video_info = json.loads(\n                get_content(r\"https://lens.zhihu.com/api/videos/{}\".format(video_id), headers=fake_headers))\n        except json.decoder.JSONDecodeError:\n            log.w(\"Video id not found:{}\".format(video_id))\n            continue\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/soimort/you-get/blob/049548f3f3f35e67ba8d3181c71fdc71d11cf260/src/you_get/extractors/zhihu.py#L1-L31","documentation":"First of two TypeError guards in zhihu_download (src/you_get/extractors/zhihu.py:13). It rejects URLs whose slash-split path list is too short to be either a Zhihu column or a question/answer page. Note the condition uses `and` (len<3 AND len<6), so in practice it only fires for very short paths like 'https://zhuanlan.zhihu.com' split into fewer than 3 parts.","triggerScenarios":"Calling zhihu_download with a bare domain or truncated URL such as 'https://zhuanlan.zhihu.com' or 'https://www.zhihu.com', producing a paths list shorter than 3 elements after url.split('/').","commonSituations":"User typos or truncates the URL; a script builds the URL from a template and drops the path segment; playlist walker passes a malformed constructed URL. The companion guard at line 18 catches well-formed but unsupported URLs (missing 'question'+'answer' or 'zhuanlan.zhihu.com').","solutions":["Pass a complete supported URL: a column https://zhuanlan.zhihu.com/p/51669862 or a question/answer https://www.zhihu.com/question/267782048/answer/490720324.","If constructing URLs programmatically, assert the path contains the required segments before calling.","Validate the URL shape upstream (regex or urlparse) so the library guard never fires.","Note the guard itself looks buggy (len(paths)<3 and len(paths)<6 is equivalent to len<3); if you maintain this fork, fix to `or` — but do not rely on that for correctness."],"exampleFix":"# before\nzhihu_download('https://zhuanlan.zhihu.com')  # TypeError\n\n# after\nzhihu_download('https://zhuanlan.zhihu.com/p/51669862')","handlingStrategy":"validation","validationCode":"import re\n\nZHIHU_OK = re.compile(\n    r'^https?://(zhuanlan\\.zhihu\\.com/p/\\d+|www\\.zhihu\\.com/question/\\d+/answer/\\d+)')\n\ndef is_supported_zhihu_url(url):\n    return bool(ZHIHU_OK.match(url))","typeGuard":"null","tryCatchPattern":"try:\n    zhihu_download(url)\nexcept TypeError as e:\n    raise ValueError('Unsupported Zhihu URL (need column or question/answer): %s' % url) from e","preventionTips":["Always pass full canonical URLs (column /p/<id> or question/answer with both ids).","Validate the URL with a regex before invoking the extractor.","When building URLs from templates, unit-test that both ids are present and numeric."],"tags":["zhihu","url-validation","extractor","typeerror"],"backgroundTag":null,"analyzedSha":"049548f3f3f35e67ba8d3181c71fdc71d11cf260","analyzedAt":"2026-08-15T03:58:15.069Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}