Skip to content

Commit

Permalink
deploy: 34a0ea3
Browse files Browse the repository at this point in the history
  • Loading branch information
ReaJason committed Mar 14, 2024
1 parent dc9a5cd commit 86b7685
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 496c554a013a2b9a9fa47504ea006d82
config: f744698d55f38bf171e6cd3e48afa688
tags: 645f666f9bcd5a90fca523b33c5a78b7
2 changes: 1 addition & 1 deletion _modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>概览:模块代码 &#8212; xhs 0.2.10 文档</title>
<title>概览:模块代码 &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
Expand Down
26 changes: 15 additions & 11 deletions _modules/xhs/core.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>xhs.core &#8212; xhs 0.2.10 文档</title>
<title>xhs.core &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../../_static/alabaster.css" />
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
Expand Down Expand Up @@ -43,7 +43,8 @@ <h1>xhs.core 源代码</h1><div class="highlight"><pre>
<span class="kn">import</span> <span class="nn">requests</span>
<span class="kn">from</span> <span class="nn">lxml</span> <span class="kn">import</span> <span class="n">etree</span>

<span class="kn">from</span> <span class="nn">xhs.exception</span> <span class="kn">import</span> <span class="n">DataFetchError</span><span class="p">,</span> <span class="n">ErrorEnum</span><span class="p">,</span> <span class="n">IPBlockError</span><span class="p">,</span> <span class="n">SignError</span>
<span class="kn">from</span> <span class="nn">xhs.exception</span> <span class="kn">import</span> <span class="p">(</span><span class="n">DataFetchError</span><span class="p">,</span> <span class="n">ErrorEnum</span><span class="p">,</span> <span class="n">IPBlockError</span><span class="p">,</span>
<span class="n">NeedVerifyError</span><span class="p">,</span> <span class="n">SignError</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">.help</span> <span class="kn">import</span> <span class="p">(</span><span class="n">cookie_jar_to_cookie_str</span><span class="p">,</span> <span class="n">download_file</span><span class="p">,</span>
<span class="n">get_imgs_url_from_note</span><span class="p">,</span> <span class="n">get_search_id</span><span class="p">,</span> <span class="n">get_valid_path_name</span><span class="p">,</span>
Expand Down Expand Up @@ -200,12 +201,17 @@ <h1>xhs.core 源代码</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="n">response</span>
<span class="k">if</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;success&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;data&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;success&quot;</span><span class="p">))</span>
<span class="k">elif</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;code&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">ErrorEnum</span><span class="o">.</span><span class="n">IP_BLOCK</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">code</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">IPBlockError</span><span class="p">(</span><span class="n">ErrorEnum</span><span class="o">.</span><span class="n">IP_BLOCK</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">msg</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;code&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">ErrorEnum</span><span class="o">.</span><span class="n">SIGN_FAULT</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">code</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">SignError</span><span class="p">(</span><span class="n">ErrorEnum</span><span class="o">.</span><span class="n">SIGN_FAULT</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">msg</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="o">==</span> <span class="mi">471</span><span class="p">:</span>
<span class="c1"># someday someone maybe will bypass captcha</span>
<span class="k">raise</span> <span class="n">NeedVerifyError</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;出现验证码,请求失败,Verifytype: </span><span class="si">{response.headers[&#39;Verifytype&#39;]}</span><span class="s2">,Verifyuuid: </span><span class="si">{response.headers[&#39;Verifyuuid&#39;]}</span><span class="s2">&quot;</span><span class="p">,</span>
<span class="n">response</span><span class="o">=</span><span class="n">response</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;code&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="n">ErrorEnum</span><span class="o">.</span><span class="n">IP_BLOCK</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">code</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">IPBlockError</span><span class="p">(</span><span class="n">ErrorEnum</span><span class="o">.</span><span class="n">IP_BLOCK</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">msg</span><span class="p">,</span> <span class="n">response</span><span class="o">=</span><span class="n">response</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;code&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="n">ErrorEnum</span><span class="o">.</span><span class="n">SIGN_FAULT</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">code</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">SignError</span><span class="p">(</span><span class="n">ErrorEnum</span><span class="o">.</span><span class="n">SIGN_FAULT</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">msg</span><span class="p">,</span> <span class="n">response</span><span class="o">=</span><span class="n">response</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">DataFetchError</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div>
<span class="k">raise</span> <span class="n">DataFetchError</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">response</span><span class="o">=</span><span class="n">response</span><span class="p">)</span></div>

<div class="viewcode-block" id="XhsClient.get"><a class="viewcode-back" href="../../source/xhs.html#xhs.XhsClient.get">[文档]</a> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">uri</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">is_creator</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">final_uri</span> <span class="o">=</span> <span class="n">uri</span>
Expand Down Expand Up @@ -266,7 +272,7 @@ <h1>xhs.core 源代码</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="n">dict_new</span>

<span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;https://www.xiaohongshu.com/explore/&quot;</span> <span class="o">+</span> <span class="n">note_id</span>
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;user-agent&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">user_agent</span><span class="p">})</span>
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;user-agent&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">user_agent</span><span class="p">,</span> <span class="s2">&quot;referer&quot;</span><span class="p">:</span> <span class="s2">&quot;https://www.xiaohongshu.com/&quot;</span><span class="p">})</span>
<span class="n">html</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">text</span>
<span class="n">state</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;window.__INITIAL_STATE__=({.*})&lt;/script&gt;&quot;</span><span class="p">,</span> <span class="n">html</span><span class="p">)[</span>
<span class="mi">0</span>
Expand Down Expand Up @@ -912,8 +918,7 @@ <h1>xhs.core 源代码</h1><div class="highlight"><pre>
<span class="n">headers</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;Referer&quot;</span><span class="p">:</span> <span class="s2">&quot;https://creator.xiaohongshu.com/&quot;</span>
<span class="p">}</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">uri</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">is_creator</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">uri</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">)</span></div>

<div class="viewcode-block" id="XhsClient.create_image_note"><a class="viewcode-back" href="../../source/xhs.html#xhs.XhsClient.create_image_note">[文档]</a> <span class="k">def</span> <span class="nf">create_image_note</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
Expand Down Expand Up @@ -973,7 +978,6 @@ <h1>xhs.core 源代码</h1><div class="highlight"><pre>
<span class="p">)</span>

<span class="n">res</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="k">if</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">][</span><span class="s2">&quot;hasFirstFrame&quot;</span><span class="p">]:</span>
<span class="n">image_id</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">][</span><span class="s2">&quot;firstFrameFileId&quot;</span><span class="p">]</span>
<span class="k">return</span> <span class="n">image_id</span>
Expand Down
2 changes: 1 addition & 1 deletion _static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '0.2.10',
VERSION: '0.2.11',
LANGUAGE: 'zh_CN',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
2 changes: 1 addition & 1 deletion basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>快速入门 &#8212; xhs 0.2.10 文档</title>
<title>快速入门 &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion crawl.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>主页爬取 &#8212; xhs 0.2.10 文档</title>
<title>主页爬取 &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion creator.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>笔记发布 &#8212; xhs 0.2.10 文档</title>
<title>笔记发布 &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>索引 &#8212; xhs 0.2.10 文档</title>
<title>索引 &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>介绍 &#8212; xhs 0.2.10 文档</title>
<title>介绍 &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion search.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>搜索 &#8212; xhs 0.2.10 文档</title>
<title>搜索 &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />

Expand Down
2 changes: 1 addition & 1 deletion source/xhs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Documentation &#8212; xhs 0.2.10 文档</title>
<title>Documentation &#8212; xhs 0.2.11 文档</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
Expand Down

0 comments on commit 86b7685

Please sign in to comment.