知识卡片
抽取网页正文先区分响应与文本
requests.get返回响应对象,写文本文件应先检查请求结果并取得相应文本,而不是直接把响应交给write。HTML get_text还可能包含代码、导航和其他非正文;需明确保留范围,避免把格式材料误当语义样本。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 用词嵌入推理
原书出处 · 1 处
- · 查看原书依据
>>> import requests >>> repo = 'https://gitlab.com/tangibleai/nlpia2/-/raw/main' >>> name = 'Chapter-06_Reasoning-with-word-embeddings-word-vectors.adoc' >>> url = f'{repo}/src/nlpia2/data/{name}' >>> adoc_text = requests.get(url) Now, you need to save that text to an ADOC file so that you can use a command-line tool to render it to HTML. Listing 6.14 Writing the ADOC string to disk >>> from pathlib import Path >>> path = Path.cwd() / name >>> with path.open('w')
参考来源
- 位置:《Natural Language Processing in Action, Second Edition》第06章《用词嵌入推理》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-6.html)
- 结论依据:摘录中关于抽取网页正文先区分响应与文本的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:>>> import requests >>> repo = 'https://gitlab.com/tangibleai/nlpia2/-/raw/main' >>> name = 'Chapter-06_Reasoning-with-word-embeddings-word-vectors.adoc' >>> url = f'{repo}/src/nlpia2/data/{name}' >>> adoc_text = requests.get(url) Now, you need to save that text to an ADOC file so that you can use a command-line tool to render it to HTML. Listing 6.14 Writing the ADOC string to disk >>> from pathlib import Path >>> path = Path.cwd() / name >>> with path.open('w')