I'm new with this and not certain what platform to use to achieve my desired outcome (i.e. php, javascript, etc.), but I'm a fast learner.
I add videos to my YouTube channel daily. After this I update two separate webpages where I manually embed the newest video URL.
Question:
I would like to automate this work process. What is the best approach (i.e. CSS, Javascript, PHP, etc.) that I can use to "get" the most current YouTube video URL and embed it into my webpage(s) automatically?
I hope I explained this properly. Let me know if you need any additional information. Thanks in advance for any guidance you can offer!!!
(1) Get link of latest video on your Channel:
You can request from Youtube, a Channel's feed using
https://www.youtube.com/feeds/videos.xml?channel_id=XXXXX
Where XXXXX is the channel's ID (as shown in browser's address bar).
The first entry in the XML document is the latest video.
Use Javascript Fetch API to load the XML or else have a JS function to call a PHP script that gives/reads back this XML document.
After correct loading, you'll have a String (text) copy of that same document existing in some variable that you put it into. The idea here is to edit the text by code (instead of highlighting and replacing the URL in a text editor). The code should find and replace the URL. The code should then save the edited text as a new HTML file (overwrite the old one using PHP)
With Javascript, either use its String functions to extract the URL or follow some tutorial about parsing XML to extract data.
(2) To update the webpages: (use PHP)
Option 1 is to load the old page and use PHP String functions to replace text of old link with latest new link. Then write the edited text as file (overwrite older HTML file)
Option 2 is to have a "template" document already stored as String in your code. Then simply replace (or add if needed) the URL of new video. Then have PHP save the text of String as an HTML file, overwriting the old .html.
Use this service, I think it will be the easiest way: https://latestyoutu.be/
You can find your channel ID by clicking Settings, Advanced, and Account Information and paste it into the site. (https://support.google.com/youtube/answer/3250431). This is probably the most hassle-free way of doing what it seems you want to.
Related
I am using iMacros for automating some form filling web task.
To avoid hard-coding certain parameters, i had planned to place the parameters in a htm file, and extract the parameters online before starting with the rest of the scripts. This way i believe, i can maintain the parameters across multiple instances running of the script, from a single place.
However, I have come across a problem, while extracting the htm file that I uploaded to google drive.
Below is the link that i want to extract data from.
https://drive.google.com/file/d/0B_GgQPGYiDg8UVBTOEYyVGk1Yk0
But looks neither the EXTRACT command nor the iMacro browser is able to extract the contents from this link.
One alternative is to host the htm file on any free web hosting platform. Buy it doesn't seems to be worth for a single file. There should be any alternate simple solution to this.
Hint: When I view source of the page, I see no tag that contains my data. Only some javascript functions.
If you want to stay with drive you can extract all the content of that file with
TAG POS=1 TYPE=DIV ATTR=class:drive-viewer-text-content EXTRACT=TXT
You will get the full HTML Code inside your file and have to parse that for the data you want. If you only really need the data in the TDs, would making it a plain text file work for you? Then you could place the individual TD contents in a single line each to make parsing your extracted data easier.
I think its better you simplify the parameters and just keep it as an array. IMacros is able to extract the text easily. Please find below my code, where I extract the text and did some basic processing and finally returned an array with the parameters.
CODE:
VERSION BUILD=9030808 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
SET !TIMEOUT_PAGE 10
URL GOTO=https://drive.google.com/file/d/0B_GgQPGYiDg8UVBTOEYyVGk1Yk0/edit
TAG POS=1 TYPE=PRE ATTR=TXT:<?xml<SP>version="1.0"?><html><SP><head><SP><title>Parameter* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}';s=s.match(/<TD>([^<]+)<.TD>/gm);s=s.map(e => e.replace('<TD>', '').replace('</TD>', ''));s;")
PROMPT {{!VAR1}}
OUTPUT:
am|am|Yes|Blocked by Administrator|Y|Y|Y|N|N|N|N|N|N|N|N|N|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y
,
pm|pm|Yes|Blocked by Administrator|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|N|N|N|N|N|N|N|N|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y
,
dt|dt|Yes|Blocked by Administrator|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y|Y
I just want to automate a web application, where that application parses the HTML page and pulls all the HTML Tags inner text based on some condition like if we have a tag called Span Example has given whose class="spanclass_1"
This is span tag...
which has particular class id. so that app parses and pulls that span into it.
And here the main pain area is, I should not use the developer code to automate that same parsing the HTML.
I want to automate that parsing done correctly, simply by using the parsed data which is shown in UI.
Any help, would be great.
Appreciating your time reading this.
(Note span tag is not shown)
Thanks buddies.
not enough details.
is this html page just a file in local filesystem on it is internet webpage?
do u have access to pages? can u modify it ? if answer yes, that just add javascript to page which will extract data and post to server.
if answer not, than it depends on language u use to programm.
Find good framework to parse html. load page parse it and extract data. Several situation can be there.
Worse scenario - page generated on client side using js.
Best scenario - page is in xhtml mode( u are lucky. any xml parser will help to build dom and extract data)
So so - page is simple html format (try several html parser to find most suitable for u)
I want to be able to programmatically (without it displaying in the browser) send an URL such as http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=platypi&sprefix=platypi%2Caps&rh=i%3Aaps%2Ck%3Aplatypi" and get back in a string (or some more appropriate data type?) the html results of the page (the interesting part, anyway) so that I could parse that and reformat selected parts of it as matched text and images (which link to the appropriate page). I want to do this with Razor/Web Pages, if that makes any difference.
IOW, this is sort of a screen-scraping question, but really a "behind-the-screen" scraping.
Is it possible? How? A 100 point post-answer-bonus will be awarded to the (or the most helpful) answer.
Use the WebClient class (or .Net 4.5's better HttpClient class) to download the HTML, then use HTML AgilityPack to parse it
I know there is a list of similar questions but all handle pages without user interaction (static even though some js may be there).
Let's say we've a page the user can interact (e.g. svg than changes, or html tables with drilldown - content changes). Those interactions will change the page. Same happens in stackoverflow when entering the question...
The idea is adding a button, "convert to pdf" taking the state of the html and sending to the user back a pdf version (we've a Java server).
Using the print of the browser is not the answer I'm looking for :-).
Is this a stick in the moon ?
You would have to store the parameters that generate the HTML view (i.e. what the user clicks on, what selections they make, etc). If you can have a list of parameters that generate the HTML view, you can have a method which accepts the list of parameters (JSON post?), generates the HTML view and passes it to your PDF generating routine. I'm not too familiar with Java libraries for this purpose, but PHP has TCPDF can take html output to basically generate a PDF for you. Certainly, there are Java libraries which will allow you to do the same thing, or you can use the parameters to get a list of rows/arrays which can be iterated over and output using the PDF library of your choice.
Both iTextPDF and Aspose.PDF would allow you to do that (I've seen them used in two different projects), but there is no magic and you will have to do some work.
The steps are roughly:
Get (as a string) the part of the document which you want to print with jQuery or innerHTML
Call a service on the server side to convert this to PDF
[Serverside] Use a whitlist - based tool to clean up the hmtl (unless you want to be hacked). JSoup is great for that.
[Serverside] Use IText or Aspose API to create the PDF from the HTML (this is not trivial, you will have to read the doc)
Download the document
I'd also recommend DocRaptor, an HTML to PDF API built by my company, Expected Behavior.
DocRaptor uses Prince XML to generate PDFs, and thus produces higher quality results than similar products.
Adding PDF generation to your own web application using our service is as simple as making an HTTP POST request to our server.
Here's a link to DocRaptor's home page:
DocRaptor
And a link to our API documentation:
DocRaptor API documentation
I'm trying to add localization support to a Google Chrome Web App and, while it is easy to define strings for manifest and CSS files, it is somewhat more difficult for HTML pages.
In the manifest and in CSS files I can simply define localization strings like so:
__MSG_name__
but this doesn't work with HTML pages.
I can make a JavaScript function to fire onload that does the job like so:
document.title = chrome.i18n.getMessage("name");
document.querySelector("span.name").innerHTML = chrome.i18n.getMessage("name");
but this seems awfully ineffecient. Furthermore, I would like to be able to specify the page metadata; application-name and description, pulling the values from the localization files. What would be the best way of doing all this?
Thanks for your help.
Please refer to this documentation:
http://code.google.com/chrome/extensions/i18n.html
If you want to add localized content within HTML, you would need to do it via JavaScript as you mentioned before. That is the only way you can do it.
chrome.i18n.getMessage("name")
It isn't inefficient to do that, you can place your JavaScript at the end of the document (right before the end body tag) and it will fill up the text with respect to the locale.
Dunno if i understand exactly what you are trying to do but you could dynamically retrieve the LANG attribute (using .getAttribute("lang") or .lang) of the targeted tag and serve accordingly the proper values.