I am in the process of moving a static HTML onto WordPress.
I am trying to figure a way in which I can pull specific HTML content from the files(title tags, description tags, <h1> tags, etc.). I have around 120 local files and doing it all by hand would be a long process.
However, if I could get this data into a CSV I can quickly move this site.
Does anyone have any advice or experience with this type of process? Any help would be greatly appreciated.
The question is about extracting certain HTML elements, out of a given HTML file. There are multiple ways to do this. Let me point out some of them below.
1) Use a script with a Library to do this. For Java use JSOUP.
String br = "<html><source>foo bar bar</source></html>";
Document doc = Jsoup.parse(br, "", Parser.xmlParser());
for (Element sentence : doc.getElementsByTag("source"))
System.out.println(sentence.text());
}
This will give you the list of elements with the HTML tag source. You can do the same for other languages like python (use BeautifulSoup) and NodeJS.
2) You can write a script to read HTML files as text files and do a search on text.
Move all your HTML files into a folder, and write a small program to load each file and search for the specific tags. Later save it to a CSV or any preferred output.
3) You can do the same with grep.
Simple do a search and load the results directly into a CSV file.
There are multiple other ways to do it. Since you mentioned that the manual workload is higher, try doing a small script to get the job done. Use the first approach as it is faster and easier.
Related
I'm working on a new Acumatica screen for our company that will require some javascript code to retrieve and display a map object (from ESRI).
This code requires an external .js file that is included to the HTML by the javascript code itself. Everything works fine if I use a blank HTML page to test this.
The problem I have is that when I try using the same code from inside the Acumatica screen, it doesn't load this required external file, and therefore the code does not work properly.
I attempted to load the full .js file code along with my code, but it returned the following error:
error CS8095: Length of String constant exceeds current memory limit. Try splitting the string into multiple constants.
I haven't tried splitting this file into multiple strings (as the error message suggests), because I want to make sure there isn't a cleaner and more professional, direct/right way to do this.
Is it possible to manually import this external .js file into our Acumatica instance, so I can point to it instead? (in case it makes a difference if it's hosted in the same environment)
or, is there any way to make Acumatica able to load external files so we can keep using our current approach? (any setting that may be preventing external files from loading?)
I'm not sure i fully understand the question. What comes to mind however is you may be looking to use the PXJavaScript control. I used this link to help get my head wrapped around how to use the control. We had a need to trigger something off with Java Script and the PXJavaScript control got us to the end result we needed. Let me know if this gets you in the right direction?
Dynamically Change Button Color
I am developing a Google App Script project that will be used right from within a Google Sheet, with HTML files as dialogs. My project will be a mix of .gs files as well as HTML files for data entry, etc. I am trying to use the methodology explained here:
https://developers.google.com/apps-script/guides/html/best-practices#separate_html_css_and_javascript
to create global JavaScript and CSS modules that I can include in my HTML files rather than cutting and pasting inline code all over the place. This will be mainly useful for the data-saving routines which capture form data, serialize it, then save it to Sheets via the methodology outlined here (and many other places): http://railsrescue.com/blog/2015-05-28-step-by-step-setup-to-send-form-data-to-google-sheets/.
The problem I am having is with trying to call the "include" statement from my HTML files, namely, lines like:
<?!= include('JavaScript'); ?>
It doesn't work when I create a menu on the spreadsheet to display my HTML file as a dialog -- the text of the include line just shows up as literal output on the dialog, and code does not appear to be getting included (not in scope).
I know the Google example is primarily for pages delpoyed via a web app, but I'd like to use my HTML files as dialogs right inside the spreadsheet (e.g. from a menu or sidebar) -- that feels nice and tidy to me. But if I can't get includes to work, my code base is going to be a nightmare and it will be really, really hard to standardize CSS across the whole app. I don't want to be cutting and pasting all the time.
So, what is the secret behind this <?! tag, and why won't it work in my HTML files when they are called as dialogs? It is clear those lines are different from the get-go (maybe not in a bad way, but they don't work), as the Google Scripting console displays those lines oddly, as depicted in the screenshot below:
Please try adding:
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
More information can be found in Adding Style Sheets.
Figured it out. I was not properly understanding the way the HTML was being served up as a dialog. I was using this behind a custom menu option:
var html = HtmlService.createHtmlOutputFromFile(htmlFileName);
when I should have been using the more dynamic:
var html = HtmlService.createTemplateFromFile(htmlFileName).evaluate();
The latter generates a user interface object where the server-side script is executed and everything is included properly when I display the object with showModalDialog() (or showSidebar()).
I just had a complete misunderstanding of how the user interface object was being created, so now all scripting works inside my HTML files.
I am using laravel, vuejs.
Its a simple question. But i need to know if it works before creating it. So what i am currently doing is
I have a WYSIWYG editor. I am saving the content from it into a html file and i am storing the location to that html file as a reference in my database
When the user requests a page, I am retrieving that html file and send the content to the page and place the content in the page.
Now to the question, I need to place adsense code between some contents in the html piece(returned from the server). The html is a whole content returned from the php server. Right?
So how can i place adsense code between each paragraph or so after the content is returned from server?
You should really consider storing content in a DB. But if you really need to store HTML in files for some reason, you can use HTML tags like !adsense! in your editor. Then just read HTML from a file and use str_replace or similar function to replace this tag with actual ad code.
As Alexey said, you may consider storing the content on the DB.
Also, you could consider actually using markdown instead of HTML, you could still use the WYSIWYG, but is easier to pre process it and easy to convert to HTML.
That being said, I second that the best option is to either use "key" to be replaced after, but that would mean giving the control to the person who edits if he wants to add the ad or not.
I would actually think you should pre process that HTML, there are some libraries to pre process it or you could use a regular expression, but, bottom line, you read the HTML before you output it, and find out what is a paragraph (depends on how your WYSIWYG is formatting things, this is why I prefer markdown), for example, you could split it in paragraphs based on the P tags or something like that, and then re assemble that, but adding the ad every X paragraphs, that way you can control how and when you put the ad, instead of the person who edits it.
To pre process the HTML you could use something like one of the following options:
Symphony DOM Crawler (recomended): http://symfony.com/doc/current/components/dom_crawler.html
PHP DOM Functions: http://php.net/manual/en/book.dom.php
A PHP HTML Parser Library: https://github.com/paquettg/php-html-parser
Or something similar.
I'm working a page that needs to fetch info from some other pages and then display parts of that information/data on the current page.
I have the HTML source code that I need to parse in a string. I'm looking for a library that can help me do this easily. (I just need to extract specific tags and the text they contain)
The HTML is well formed (All closing/ending tags present).
I've looked at some options but they are all being extremely difficult to work with for various reasons.
I've tried the following solutions:
jkl-parsexml library (The library js file itself throws up HTTPError 101)
jQuery.parseXML Utility (Didn't find much documentation/many examples to figure out what to do)
XPATH (The Execute statement is not working but the JS Error Console shows no errors)
And so I'm looking for a more user friendly library or anything(tutorials/books/references/documentation) that can let me use the aforementioned tools better, more easily and efficiently.
An Ideal solution would be something like BeautifulSoup available in Python.
Using jQuery, it would be as simple as $(HTMLstring); to create a jQuery object with the HTML data from the string inside it (this DOM would be disconnected from your document). From there it's very easy to do whatever you want with it--and traversing the loaded data is, of course, a cinch with jQuery.
You can do something like this:
$("string with html here").find("jquery selector")
$("string with html here") this will create a document fragment and put an html into it (basically, it will parse your HTML). And find will search for elements in that document fragment (and only inside it). At the same time it will not put it in page DOM
I wanted to give my users a little piece of JavaScript or HTML code that they could put on their site and show information about them. Kind of like StackOverFlows new feature Flair.
I have an idea of how to code it. I was going to give them some JS with a HTML that had a DIV id="MySite_Info". Then the JS would go to my site and pull some JSON or XML and then fill in the data with a DIV in the HTML I gave them on their site.
Is there a better way to do this? Or any examples online I should follow? Whats the best way to create these javascript snippets? (Not sure what the proper name is)
There are two basic options.
Images (and pictures of text suck)
JavaScript - as you described
The approach I would take would be to:
Dynamically generate the JS using a server side process. This would include data for the user (using a JSON generator to easily produce the data in a suitable format).
Build the badge using standard DOM methods
Find the element with the document id and appendChild the generated badge