Skip to content

Commit

Permalink
you can now create handlers with either 1 or 2 params, if the second …
Browse files Browse the repository at this point in the history
…param is specified, it will hold the Tab object. Tab also got a method feed_cdp. both are meant for especially the fetch domain, which otherwise blocks the entire operation. an example of how it can be used is in examples/fetch_domain.py.
  • Loading branch information
ultrafunkamsterdam committed Aug 11, 2024
1 parent 2019f9f commit e630abf
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 37 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# NODRIVER

## [CLICK HERE FOR DOCS](https://ultrafunkamsterdam.github.io/nodriver/)

**This package provides next level webscraping and browser automation
using a relatively simple interface.**

Expand All @@ -22,7 +24,7 @@ While usability and convenience is important. It’s also easy
to fully customizable everything using the entire array of
[CDP](https://chromedevtools.github.io/devtools-protocol/) domains, methods and events available.

## Some features
### Some features

* A blazing fast undetected chrome (-ish) automation library
* No chromedriver binary or Selenium dependency
Expand Down Expand Up @@ -59,7 +61,7 @@ to fully customizable everything using the entire array of
* ```first_submit_button = await tab.select(selector='button[type=submit]')```
* ```inputs_in_form = await tab.select_all('form input')``` -->

### Installation
#### Installation

Since it’s a part of undetected-chromedriver, installation goes via

Expand All @@ -78,7 +80,7 @@ pip install nodriver

<a id="getting-started-commands"></a>

### usage example
#### usage example

The aim of this project (just like undetected-chromedriver, somewhere long ago)
is to keep it short and simple, so you can quickly open an editor or interactive session,
Expand Down
1 change: 0 additions & 1 deletion docs/_build/html/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ <h1>All modules for which code is available</h1>
<li><a href="nodriver/core/_contradict.html">nodriver.core._contradict</a></li>
<li><a href="nodriver/core/browser.html">nodriver.core.browser</a></li>
<li><a href="nodriver/core/config.html">nodriver.core.config</a></li>
<li><a href="nodriver/core/connection.html">nodriver.core.connection</a></li>
<li><a href="nodriver/core/element.html">nodriver.core.element</a></li>
<li><a href="nodriver/core/tab.html">nodriver.core.tab</a></li>
</ul>
Expand Down
3 changes: 3 additions & 0 deletions docs/_build/html/_modules/nodriver/core/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ <h1>Source code for nodriver.core.browser</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="o">.</span><span class="n">_i</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tabs</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">main_tab</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span>

<span class="k">def</span> <span class="fm">__reversed__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">reversed</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tabs</span><span class="p">))</span>

<span class="k">def</span> <span class="fm">__next__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tabs</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_i</span><span class="p">]</span>
Expand Down
35 changes: 19 additions & 16 deletions docs/_build/html/_modules/nodriver/core/tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -1689,13 +1689,12 @@ <h1>Source code for nodriver.core.tab</h1><div class="highlight"><pre>
<span class="k">await</span> <span class="bp">self</span>

<span class="c1"># there must be a better way...</span>
<span class="n">origin</span> <span class="o">=</span> <span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">origin</span> <span class="o">=</span> <span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

<span class="n">items</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">get_dom_storage_items</span><span class="p">(</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">StorageId</span><span class="p">(</span>
<span class="n">is_local_storage</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">security_origin</span><span class="o">=</span><span class="n">origin</span><span class="p">))</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">StorageId</span><span class="p">(</span><span class="n">is_local_storage</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">security_origin</span><span class="o">=</span><span class="n">origin</span><span class="p">)</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="n">retval</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
Expand All @@ -1718,18 +1717,22 @@ <h1>Source code for nodriver.core.tab</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">target</span><span class="o">.</span><span class="n">url</span><span class="p">:</span>
<span class="k">await</span> <span class="bp">self</span>
<span class="c1"># there must be a better way...</span>
<span class="n">origin</span> <span class="o">=</span> <span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">gather</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">set_dom_storage_item</span><span class="p">(</span>
<span class="n">storage_id</span><span class="o">=</span><span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">StorageId</span><span class="p">(</span>
<span class="n">is_local_storage</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">security_origin</span><span class="o">=</span><span class="n">origin</span>
<span class="p">),</span>
<span class="n">key</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">key</span><span class="p">),</span>
<span class="n">value</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">),</span>
<span class="p">)</span>
<span class="p">)</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">items</span><span class="o">.</span><span class="n">items</span><span class="p">()])</span></div>
<span class="n">origin</span> <span class="o">=</span> <span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">url</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="mi">3</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">gather</span><span class="p">(</span>
<span class="o">*</span><span class="p">[</span>
<span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span>
<span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">set_dom_storage_item</span><span class="p">(</span>
<span class="n">storage_id</span><span class="o">=</span><span class="n">cdp</span><span class="o">.</span><span class="n">dom_storage</span><span class="o">.</span><span class="n">StorageId</span><span class="p">(</span>
<span class="n">is_local_storage</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">security_origin</span><span class="o">=</span><span class="n">origin</span>
<span class="p">),</span>
<span class="n">key</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">key</span><span class="p">),</span>
<span class="n">value</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">),</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">items</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
<span class="p">]</span>
<span class="p">)</span></div>


<span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span>
Expand Down
2 changes: 2 additions & 0 deletions docs/_build/html/_sources/readme.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
NODRIVER
##################

`CLICK HERE FOR DOCS <https://ultrafunkamsterdam.github.io/nodriver/>`_
____

**This package provides next level webscraping and browser automation
using a relatively simple interface.**
Expand Down
6 changes: 4 additions & 2 deletions docs/_build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,8 @@ <h2>F</h2>
<li><a href="nodriver/cdp/audits.html#nodriver.cdp.audits.FederatedAuthUserInfoRequestIssueDetails">FederatedAuthUserInfoRequestIssueDetails (class in nodriver.cdp.audits)</a>
</li>
<li><a href="nodriver/cdp/audits.html#nodriver.cdp.audits.FederatedAuthUserInfoRequestIssueReason">FederatedAuthUserInfoRequestIssueReason (class in nodriver.cdp.audits)</a>
</li>
<li><a href="nodriver/classes/tab.html#nodriver.Tab.feed_cdp">feed_cdp() (Tab method)</a>
</li>
<li><a href="nodriver/cdp/page.html#nodriver.cdp.page.BackForwardCacheNotRestoredReason.FENCED_FRAMES_EMBEDDER">FENCED_FRAMES_EMBEDDER (BackForwardCacheNotRestoredReason attribute)</a>
</li>
Expand Down Expand Up @@ -3558,11 +3560,11 @@ <h2>F</h2>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.FontFace.font_style">font_style (FontFace attribute)</a>
</li>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.FontFace.font_variant">font_variant (FontFace attribute)</a>
</li>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.FontFace.font_variation_axes">font_variation_axes (FontFace attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.FontFace.font_variation_axes">font_variation_axes (FontFace attribute)</a>
</li>
<li><a href="nodriver/cdp/css.html#nodriver.cdp.css.FontFace.font_weight">font_weight (FontFace attribute)</a>

<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/_build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ <h4>Main objects<a class="headerlink" href="#main-objects" title="Link to this h
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.closed"><code class="docutils literal notranslate"><span class="pre">Tab.closed</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.download_file"><code class="docutils literal notranslate"><span class="pre">Tab.download_file()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.evaluate"><code class="docutils literal notranslate"><span class="pre">Tab.evaluate()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.feed_cdp"><code class="docutils literal notranslate"><span class="pre">Tab.feed_cdp()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.find"><code class="docutils literal notranslate"><span class="pre">Tab.find()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.find_all"><code class="docutils literal notranslate"><span class="pre">Tab.find_all()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="nodriver/classes/tab.html#nodriver.Tab.find_element_by_text"><code class="docutils literal notranslate"><span class="pre">Tab.find_element_by_text()</span></code></a></li>
Expand Down
22 changes: 22 additions & 0 deletions docs/_build/html/nodriver/classes/tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,27 @@ <h2><a class="reference internal" href="#nodriver.Tab.send" title="nodriver.Tab.
<em class="property"><span class="pre">async</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">evaluate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expression</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">await_promise</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">return_by_value</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/nodriver/core/tab.html#Tab.evaluate"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodriver.Tab.evaluate" title="Link to this definition">#</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="nodriver.Tab.feed_cdp">
<span class="sig-name descname"><span class="pre">feed_cdp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cdp_obj</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nodriver.Tab.feed_cdp" title="Link to this definition">#</a></dt>
<dd><p>used in specific cases, mostly during cdp.fetch.RequestPaused events,
in which the browser literally blocks. using feed_cdp you can issue
a response without a blocking “await”.</p>
<p>note: this method won’t cause a response.
note: this is not an async method, just a regular method!</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>cdp_obj</strong></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p></p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="nodriver.Tab.find">
<em class="property"><span class="pre">async</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">find</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">best_match</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">return_enclosing_element</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/nodriver/core/tab.html#Tab.find"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodriver.Tab.find" title="Link to this definition">#</a></dt>
Expand Down Expand Up @@ -1125,6 +1146,7 @@ <h2><a class="reference internal" href="#nodriver.Tab.send" title="nodriver.Tab.
<li><a class="reference internal" href="#nodriver.Tab.closed"><code class="docutils literal notranslate"><span class="pre">Tab.closed</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.download_file"><code class="docutils literal notranslate"><span class="pre">Tab.download_file()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.evaluate"><code class="docutils literal notranslate"><span class="pre">Tab.evaluate()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.feed_cdp"><code class="docutils literal notranslate"><span class="pre">Tab.feed_cdp()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.find"><code class="docutils literal notranslate"><span class="pre">Tab.find()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.find_all"><code class="docutils literal notranslate"><span class="pre">Tab.find_all()</span></code></a></li>
<li><a class="reference internal" href="#nodriver.Tab.find_element_by_text"><code class="docutils literal notranslate"><span class="pre">Tab.find_element_by_text()</span></code></a></li>
Expand Down
Binary file modified docs/_build/html/objects.inv
Binary file not shown.
Loading

0 comments on commit e630abf

Please sign in to comment.