A toolkit of Doraemon
Project description
Doraemon is a toolkit including frequently used code. It is still in development...
Installation
pip install Doraemon
Checklist
- Google Knowledge Graph
- Google Translator
- Robust Requests
- User-friendly Chrome
Example
##1. Google Knowledge Graph
from Doraemon.OnlineSearch import google_KG
def get_proxies():
proxy_str = "127.0.0.1:1080"
proxies = {"http": "http://%s" % proxy_str,
"https": "http://%s" % proxy_str, }
return proxies
res = google_KG.get_entity("alibaba", get_proxies_fun=get_proxies)
print(res)
##2. Google Translator
from Doraemon.OnlineSearch import google_translator
def get_proxies():
proxy_str = "127.0.0.1:1080"
proxies = {"http": "http://%s" % proxy_str,
"https": "http://%s" % proxy_str, }
return proxies
ori_text = "中华民国"
res1 = google_translator.trans(ori_text, tl="zh-TW", get_proxies_fun=get_proxies)
long_text = ori_text * 2500
res2 = google_translator.trans_long(long_text, )# if len(text) > 5000
print(res1)
print(res2)
##3. Robust Requests
from Doraemon.Requests import requests_dora
url = "https://www.baidu.com"
headers = requests_dora.get_default_headers()
headers["User-Agent"] = requests_dora.get_random_user_agent()
def get_proxies():
proxy_str = "127.0.0.1:1080"
proxies = {"http": "http://%s" % proxy_str,
"https": "http://%s" % proxy_str, }
return proxies
# max_times, get_proxies_fun, and invoked_by is optional, other parameters are the same as the requests.get() and requests.post()
res1 = requests_dora.try_best_2_get(url, max_times=5, get_proxies_fun=get_proxies, invoked_by="parent_fun_name")
res2 = requests_dora.try_best_2_post(url, max_times=5, get_proxies_fun=get_proxies)
print(res1.status_code)
print(res2.status_code)
##4. User-friendly Chrome
from Doraemon.Requests import chrome_dora
proxy = "127.0.0.1:1080"
baidu_url = "https://www.baidu.com"
# no_images: do not load images(response more quickly)
# headless: make the chrome invisible
# proxy: set if you need
# they are all optional
chrome = chrome_dora.MyChrome(headless=False, proxy="127.0.0.1:1080", no_images=True)
chrome.get(baidu_url)
print(chrome.page_source)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Doraemon-0.3.tar.gz
(10.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Doraemon-0.3.tar.gz.
File metadata
- Download URL: Doraemon-0.3.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13c1d939a174a7c9edebc5783420cdde2b0a4bc3937210c2a4ae5f2cf326f43f
|
|
| MD5 |
8041672a25d9ec3fb8780e6fa8bc176a
|
|
| BLAKE2b-256 |
ddb9d0d12c6d01f4c83c5b6ac2dfadac8270e3e53d2c61fc1b1dcf8622a3fce9
|
File details
Details for the file Doraemon-0.3-py2.py3-none-any.whl.
File metadata
- Download URL: Doraemon-0.3-py2.py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5534d491e2263d68e708b85db4c76d74893c7e816c7ca5b5c285b31bc35a2dde
|
|
| MD5 |
d1e2d60670c0c908b2c7c5af27d9e860
|
|
| BLAKE2b-256 |
c93dd538d8943c17c9254bacb973cd4fbbea7eb7c80247abb70490415c2e04ef
|