A
A
Anton2019-07-31 01:17:53
Parsing
Anton, 2019-07-31 01:17:53

Extracting data from a web page, how?

Please tell me, is it possible to somehow extract data (for example, some kind of number) from the web page that I currently open and save it to a text file?
Interested in the local method.
Maybe some special browser or program?
Is it possible?
For example, now I have a web page with this question open and I want to write only the text of the question to a text file.
Windows environment.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Gip, 2019-07-31
@Giperoglif

Greasemonkey
https://en.wikipedia.org/wiki/Greasemonkey

S
Sergey c0re, 2019-07-31
@erge

watch the videos:
https://www.youtube.com/results?search_query=chrom...
switch to chrome debug mode by pressing F12
in debug mode press Ctrl+shift+C , then hover over the question text on the page and click, on the right in debugging, the source with the specified element will open

<div class="question__text js-question-text" itemprop="text description">
....

to get the text of this element , select it with a selector by the class attribute and take the content
by executing the following code in the console of the debug window:
let text = document.querySelector(".question__text.js-question-text").textContent;
console.log(text);

but to write it to a file, you need to write a browser extension (Chrome-Extenstions), see how extensions are made.
from the extension, you can write a file, for example like this:
let obj = {
    "filename": "file.txt",
    "url": 'text/plain;charset=UTF-8,' + encodeURIComponent(text),
    "conflictAction": "prompt",
    "saveAs": true
  };
chrome.downloads.download(obj);

See chrome.downloads
Here's an option to save the element's text from the browser console:
let text = document.querySelector(".question__text.js-question-text").textContent;
let a = document.createElement("a");
a.setAttribute("href", "data:text/plane;base64,"+window.btoa(unescape(encodeURIComponent(text))));
a.setAttribute("download","YourFileName.txt");
a.click();

In addition, the script above can be formatted as a bookmarklet
right as it is:
or by wrapping it in a function:
thus, clicking on the bookmarklet link in the favorites will call this script and save the text.

H
HappyMen, 2019-07-31
@HappyMen

You can write js code (as an extension for example) that will parse the text and send it to your server where there will be a php handler that will already process the request and create a text editor with your text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question