Releases: ClericPy/ichrome
Releases · ClericPy/ichrome
4.0.2
4.0.1
- add webapp route for /request_get to send get request with headers,proxy
# ======================= server code ===========================
from inspect import getsource
import requests
# 1. request_get demo
print(
requests.get(
"http://127.0.0.1:8009/chrome/request_get",
params={
"__url": "http://httpbin.org/get?a=1", # [required] target URL
"__proxy": "http://127.0.0.1:1080", # [optional]
"__timeout": "10", # [optional]
"my_query": "OK", # [optional] params for target URL
},
# headers for target URL
headers={
"User-Agent": "OK",
"my_header": "OK",
"Cookie": "my_cookie1=OK",
},
# cookies={"my_cookie2": "OK"}, # [optional] cookies for target URL if headers["Cookie"] is None
).text,
flush=True,
)
# <html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{
# "args": {
# "a": "1",
# "my_query": "OK"
# },
# "headers": {
# "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
# "Accept-Encoding": "gzip, deflate",
# "Cookie": "my_cookie1=OK",
# "Host": "httpbin.org",
# "My-Header": "OK",
# "Upgrade-Insecure-Requests": "1",
# "User-Agent": "OK",
# "X-Amzn-Trace-Id": "Root=1-654d0664-74457b4317c2f41d17b6a823"
# },
# "origin": "1.1.1.1",
# "url": "http://httpbin.org/get?a=1&my_query=OK"
# }
# </pre></body></html>
# '"Herman Melville - Moby-Dick"'
# "<html><head><meta name=\"color-scheme\" content=\"light dark\"></head><body><pre style=\"word-wrap: break-word; white-space: pre-wrap;\">{\n \"origin\": \"103.171.177.94\"\n}\n</pre></body></html>"
# 2. test tab_callback
async def tab_callback(self, tab, data, timeout):
await tab.set_url(data["url"], timeout=timeout)
return (await tab.querySelector("h1")).text
r = requests.post(
"http://127.0.0.1:8009/chrome/do",
json={
"data": {"url": "http://httpbin.org/html"},
"tab_callback": getsource(tab_callback),
"timeout": 10,
},
)
print(repr(r.text), flush=True)
'"Herman Melville - Moby-Dick"'
async def tab_callback(task, tab, data, timeout):
await tab.wait_loading(3)
return await tab.html
# 3. incognito_args demo
print(
requests.post(
"http://127.0.0.1:8009/chrome/do",
json={
"tab_callback": getsource(tab_callback),
"timeout": 10,
"incognito_args": {
"url": "http://httpbin.org/ip",
"proxyServer": "http://127.0.0.1:1080",
},
},
).text
)
# "<html><head><meta name=\"color-scheme\" content=\"light dark\"></head><body><pre style=\"word-wrap: break-word; white-space: pre-wrap;\">{\n \"origin\": \"103.171.177.94\"\n}\n</pre></body></html>"
4.0.0
- add retry for clear_dir_with_shutil
- add shutdown_reason for daemon
- use ruff-format instead of yapf
- add tab.run_js_snippets
- remove
ichrome.sync
. new sync mode with ichrome.debugger. #139 https://github.com/ClericPy/ichrome/blob/master/examples_debug.py - rm null main_data_dir if _use_port_dir
v3.2.0
- add Tab.info, Tab.get_info, Tab.new_tab, Tab.browserContextId, Tab.get_targets
Tab.new_tab demo
import asyncio
from ichrome import AsyncChromeDaemon
async def main():
async with AsyncChromeDaemon(headless=False, disable_image=True) as cd:
async with cd.incognito_tab() as tab:
url = 'http://www.bing.com/'
await tab.goto(url, timeout=3)
MUIDB = (await tab.get_cookies_dict([url])).get('MUIDB')
new_tab = await tab.new_tab()
tab_exist = bool(await tab.chrome.get_tab(new_tab.tab_id))
assert tab_exist
async with new_tab(auto_close=True) as tab:
# same context, so same cookie
MUIDB2 = (await tab.get_cookies_dict([url])).get('MUIDB')
# print(MUIDB, MUIDB2, MUIDB == MUIDB2)
assert MUIDB == MUIDB2
# the new_tab auto closed
tab_exist = bool(await tab.chrome.get_tab(new_tab.tab_id))
assert not tab_exist
asyncio.run(main())
3.1.1
- fix missing tab0 while start_url is null, now default start_url is "about:blank"
- add
ChromeDaemon.cleanup_launched_pids
to atexit to kill all the chrome processes whichichrome
launched.- kill the chrome processed which not exiting
- update
tab.iter_fetch
methods- now
tab.iter_fetch
will containnetworkId
to get response body whilerequestStage
isResponse
. - add
get_response
for events - add
match_event
to filt the events with RequestPattern
- now
- new version chrome forbidden
GET
method towards/json/new
fixed #123
3.1.0
3.0.9
3.0.7
3.0.4
3.0.3
3.0.2 ~ 3.0.3
- add kwargs & callback for EventBuffer fixed #89
- add captureBeyondViewport for screenshot
pool
Use incognico mode by default, or you can se ChromeEngine.DEFAULT_INCOGNITO_ARGS = None to use normal mode- different hosts of chrome processes are killed by the same port #94 fixed
- Not Support edge browser #92 fix
- fix Identifier 'node' has already been declared
- ChromeRuntimeError(f'[closed] {self} ws has been closed') fix