Data Submission¶
The darc project integrates the capability of submitting
fetched data and information to a web server, to support real-time
cross-analysis and status display.
There are three submission events:
New Host Submission –
API_NEW_HOSTSubmitted in
crawler()function call, when the crawling URL is marked as a new host.Requests Submission –
API_REQUESTSSubmitted in
crawler()function call, after the crawling process of the URL usingrequests.Selenium Submission –
API_SELENIUMSubmitted in
loader()function call, after the loading process of the URL usingselenium.
See also
Please refer to data schema for more information about the submission data.
- darc.submit.get_hosts(link)[source]¶
Read
hosts.txt.
- darc.submit.get_robots(link)[source]¶
Read
robots.txt.
- darc.submit.get_sitemaps(link)[source]¶
Read sitemaps.
- Parameters:
link (
Link) – Link object to read sitemaps.- Return type:
- Returns:
- darc.submit.save_submit(domain, data)[source]¶
Save failed submit data.
- Parameters:
- Return type:
Notes
The saved files will be categorised by the actual runtime day for better maintenance.
- darc.submit.submit_new_host(time, link, partial=False, force=False)[source]¶
Submit new host.
When a new host is discovered, the
darccrawler will submit the host information. Such includesrobots.txt(if exists) andsitemap.xml(if any).- Parameters:
time (datetime.datetime) – Timestamp of submission.
link (
Link) – Link object of submission.partial (
bool) – If the data is not complete, i.e. failed when fetchingrobots.txt,hosts.txtand/or sitemaps.force (
bool) – If the data is force re-fetched, i.e. cache expired when checking withdarc.db.have_hostname().
- Return type:
If
API_NEW_HOSTisNone, the data for submission will directly be save throughsave_submit().The data submitted should have following format:
{ // partial flag - true / false "$PARTIAL$": ..., // force flag - true / false "$FORCE$": ..., // metadata of URL "[metadata]": { // original URL - <scheme>://<netloc>/<path>;<params>?<query>#<fragment> "url": ..., // proxy type - null / tor / i2p / zeronet / freenet "proxy": ..., // hostname / netloc, c.f. ``urllib.parse.urlparse`` "host": ..., // base folder, relative path (to data root path ``PATH_DATA``) in containter - <proxy>/<scheme>/<host> "base": ..., // sha256 of URL as name for saved files (timestamp is in ISO format) // JSON log as this one - <base>/<name>_<timestamp>.json // HTML from requests - <base>/<name>_<timestamp>_raw.html // HTML from selenium - <base>/<name>_<timestamp>.html // generic data files - <base>/<name>_<timestamp>.dat "name": ..., // originate URL - <scheme>://<netloc>/<path>;<params>?<query>#<fragment> "backref": ... }, // requested timestamp in ISO format as in name of saved file "Timestamp": ..., // original URL "URL": ..., // robots.txt from the host (if not exists, then ``null``) "Robots": { // path of the file, relative path (to data root path ``PATH_DATA``) in container // - <proxy>/<scheme>/<host>/robots.txt "path": ..., // content of the file (**base64** encoded) "data": ..., }, // sitemaps from the host (if none, then ``null``) "Sitemaps": [ { // path of the file, relative path (to data root path ``PATH_DATA``) in container // - <proxy>/<scheme>/<host>/sitemap_<name>.xml "path": ..., // content of the file (**base64** encoded) "data": ..., }, ... ], // hosts.txt from the host (if proxy type is ``i2p``; if not exists, then ``null``) "Hosts": { // path of the file, relative path (to data root path ``PATH_DATA``) in container // - <proxy>/<scheme>/<host>/hosts.txt "path": ..., // content of the file (**base64** encoded) "data": ..., } }
- darc.submit.submit_requests(time, link, response, session, content, mime_type, html=True)[source]¶
Submit requests data.
When crawling, we’ll first fetch the URl using
requests, to check its availability and to save its HTTP headers information. Such information will be submitted to the web UI.- Parameters:
time (datetime.datetime) – Timestamp of submission.
link (
Link) – Link object of submission.response (requests.Response) – Response object of submission.
session (requests.Session) – Session object of submission.
content (
bytes) – Raw content of from the response.mime_type (
str) – Content type.html (
bool) – If current document is HTML or other files.
- Return type:
If
API_REQUESTSisNone, the data for submission will directly be save throughsave_submit().The data submitted should have following format:
{ // metadata of URL "[metadata]": { // original URL - <scheme>://<netloc>/<path>;<params>?<query>#<fragment> "url": ..., // proxy type - null / tor / i2p / zeronet / freenet "proxy": ..., // hostname / netloc, c.f. ``urllib.parse.urlparse`` "host": ..., // base folder, relative path (to data root path ``PATH_DATA``) in containter - <proxy>/<scheme>/<host> "base": ..., // sha256 of URL as name for saved files (timestamp is in ISO format) // JSON log as this one - <base>/<name>_<timestamp>.json // HTML from requests - <base>/<name>_<timestamp>_raw.html // HTML from selenium - <base>/<name>_<timestamp>.html // generic data files - <base>/<name>_<timestamp>.dat "name": ..., // originate URL - <scheme>://<netloc>/<path>;<params>?<query>#<fragment> "backref": ... }, // requested timestamp in ISO format as in name of saved file "Timestamp": ..., // original URL "URL": ..., // request method "Method": "GET", // response status code "Status-Code": ..., // response reason "Reason": ..., // response cookies (if any) "Cookies": { ... }, // session cookies (if any) "Session": { ... }, // request headers (if any) "Request": { ... }, // response headers (if any) "Response": { ... }, // content type "Content-Type": ..., // requested file (if not exists, then ``null``) "Document": { // path of the file, relative path (to data root path ``PATH_DATA``) in container // - <proxy>/<scheme>/<host>/<name>_<timestamp>_raw.html // or if the document is of generic content type, i.e. not HTML // - <proxy>/<scheme>/<host>/<name>_<timestamp>.dat "path": ..., // content of the file (**base64** encoded) "data": ..., }, // redirection history (if any) "History": [ // same record data as the original response {"...": "..."} ] }See also
darc.submit.get_raw()
- darc.submit.submit_selenium(time, link, html, screenshot)[source]¶
Submit selenium data.
After crawling with
requests, we’ll then render the URl usingseleniumwith Google Chrome and its web driver, to provide a fully rendered web page. Such information will be submitted to the web UI.- Parameters:
time (datetime.datetime) – Timestamp of submission.
link (
Link) – Link object of submission.html (
str) – HTML source of the web page.
- Return type:
If
API_SELENIUMisNone, the data for submission will directly be save throughsave_submit().Note
This information is optional, only provided if the content type from
requestsis HTML, status code not between400and600, and HTML data not empty.The data submitted should have following format:
{ // metadata of URL "[metadata]": { // original URL - <scheme>://<netloc>/<path>;<params>?<query>#<fragment> "url": ..., // proxy type - null / tor / i2p / zeronet / freenet "proxy": ..., // hostname / netloc, c.f. ``urllib.parse.urlparse`` "host": ..., // base folder, relative path (to data root path ``PATH_DATA``) in containter - <proxy>/<scheme>/<host> "base": ..., // sha256 of URL as name for saved files (timestamp is in ISO format) // JSON log as this one - <base>/<name>_<timestamp>.json // HTML from requests - <base>/<name>_<timestamp>_raw.html // HTML from selenium - <base>/<name>_<timestamp>.html // generic data files - <base>/<name>_<timestamp>.dat "name": ..., // originate URL - <scheme>://<netloc>/<path>;<params>?<query>#<fragment> "backref": ... }, // requested timestamp in ISO format as in name of saved file "Timestamp": ..., // original URL "URL": ..., // rendered HTML document (if not exists, then ``null``) "Document": { // path of the file, relative path (to data root path ``PATH_DATA``) in container // - <proxy>/<scheme>/<host>/<name>_<timestamp>.html "path": ..., // content of the file (**base64** encoded) "data": ..., }, // web page screenshot (if not exists, then ``null``) "Screenshot": { // path of the file, relative path (to data root path ``PATH_DATA``) in container // - <proxy>/<scheme>/<host>/<name>_<timestamp>.png "path": ..., // content of the file (**base64** encoded) "data": ..., } }See also
darc.submit.get_html()darc.submit.get_screenshot()
- darc.submit.PATH_API = '{PATH_DB}/api/'¶
Path to the API submittsion records, i.e.
apifolder under the root of data storage.See also
- darc.submit.API_NEW_HOST: str¶
API URL for
submit_new_host().- Default:
- Environ:
- darc.submit.API_REQUESTS: str¶
API URL for
submit_requests().- Default:
- Environ:
- darc.submit.API_SELENIUM: str¶
API URL for
submit_selenium().- Default:
- Environ:
Note
If API_NEW_HOST, API_REQUESTS
and API_SELENIUM is None, the corresponding
submit function will save the JSON data in the path
specified by PATH_API.