How to EXTRACT and save Url in CSV using IMACROS - csv

Trying to get contents and saving them in a CSV, one per row
But when it has a WEBLINK, the URL gets messed up.
See the latest
Actually the glassdoor.com/Top-Companies-... part is a hyperlink to following weblink
http://t.co/tDbVGX48c6
which redirects to
http://www.glassdoor.com/Top-Companies-for-Culture-and-Values-LST_KQ0,36.htm
**ISSUE is if we use the following to save this **
TAG POS=1 TYPE=DIV ATTR=CLASS:dir-ltr EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=* FILE=Save.csv
it is saved in CSV as following only (i.e TEXT) & the link is not saved properly.
Honored to be named #Glassdoor's top company for culture and values. #jointheflock glassdoor.com/Top-Companies-...
**How can we make sure we get ACTUAL link saved in CSV, for every one
I feel EVAL & thus Javascript command can be used but i am not sure how.
I am using WINDOWS XP 64 Bit with Latest Firefox Imacros Addon
Thanks

Take a look at the EXTRACT definition on the iMacros wiki. You can use HREF as the extract type to extract the link instead of the text for that anchor. The following example extracts the link and saved it to a file.
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://www.penny-arcade.com/
TAG POS=1 TYPE=A ATTR=TXT:Forum EXTRACT=HREF
SAVEAS TYPE=EXTRACT FOLDER=* FILE=FORUMS.CSV
Here is the macro code for the twitter page:
TAG POS=1 TYPE=A ATTR=CLASS:twitter-timeline-link EXTRACT=HREF
SAVEAS TYPE=EXTRACT FOLDER=* FILE=SaveTweets.csv
Here is a javascript version that pulls each tweet and a link it if exists.
var retcode, tagText, tweetCounter, startIndex, endIndex, macro, extractMacro;
extractMacro = "";
macro = "CODE:";
macro += "URL GOTO=https://twitter.com/twitter\n";
retcode = iimPlay(macro);
tweetCounter = 1;
do
{
extractMacro = "CODE:";
macro = "CODE:";
macro += "TAG POS=" + tweetCounter + " TYPE=P ATTR=CLASS:ProfileTweet-text<SP>js-tweet-text<SP>u-dir EXTRACT=TXT\n";
retcode = iimPlay(macro);
tagText = iimGetLastExtract();
// iMacros code requires <SP> for spaces
tagText = tagText.replace(/[ \s\t\n]/g, "<SP>");
// Add extracted value to another macro for extraction later
extractMacro += "ADD !EXTRACT " + tagText + "\n";
macro = "CODE:";
macro += "TAG POS=" + tweetCounter + " TYPE=DIV ATTR=CLASS:ProfileTweet-Contents EXTRACT=HTM\n";
retcode = iimPlay(macro);
tagHTML = iimGetLastExtract();
tweetCounter++;
startIndex = 0;
do
{
startIndex = tagHTML.indexOf("data-expanded-url=", startIndex + 1);
endIndex = tagHTML.indexOf(" ", startIndex);
if (startIndex > 0)
{
var linkText = tagHTML.substring(startIndex + 'data-expanded-url="'.length, endIndex - 1);
// iMacros code requires <SP> for spaces
linkText = linkText.replace(/[ \s\t\n]/g, "<SP>");
extractMacro += "ADD !EXTRACT " + linkText + "\n";
}
} while (startIndex > 0);
// Save extracted data
extractMacro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=SaveTweets.csv\n";
retcode = iimPlay(extractMacro);
}
while (tagText !== "#EANF#");

Related

How to program a URL? (For search query)

A co-worker of mine shared an autohotkey script (it's actually an exe file that runs on the background). Anyways, when I click the hotkeys it opens up a company webiste and creates a shared query for whatever's on the clipboard. I was wondering how this is done and how I can make my own.
I'm specially curious about the "URL" modification that includes all these search options:
https://<COMPANYWEBSITE>/GotoDocumentSearch.do
That's the URL where I can search (sorry it's restricted and even if I link it you cant access it).
Anyways, after I set up all my options and stuff and click the search button I get the following URL:
https://<COMPANYWEBSITE>/DocumentSearch.do
I inspected the website source and this is the function that's called when I press the search button:
function preSubmitSearch(docPress) {
document.pressed = docPress;
// setup local doc types for submit by lopping over multi selects and building json data string
var localDocTypesJson = "{";
var sep = "";
jQuery(".localTypeSel").each(function (i) {
var selLocalTypes = jQuery(this).multiselect("getChecked");
// get doc type code from id ex. 'localTypeSel_PD'
//window.console.log("this.id=" + this.id);
var tmpArr = this.id.split("_");
var docTypeCode = tmpArr[1];
var selLocalTypesCnt = selLocalTypes.length;
if (selLocalTypesCnt > 0) {
var localTypes = "";
var sep2 = "";
for (var i2 = 0; i2 < selLocalTypesCnt; i2++) {
localTypes += sep2 + "\"" + selLocalTypes[i2].value + "\"";
sep2 = ",";
}
localDocTypesJson += sep + "\"" + docTypeCode + "\": [" + localTypes + "]";
sep = ",";
}
});
localDocTypesJson += "}";
jQuery("#localDocTypesJson").val(localDocTypesJson);
}
HOWEVER, the working code that was shared with me (that was written ages ago by some employee who's not here anymore). Has the following URL when I use the autohotkey:
https://<COMPANYWEBSITE>/DocumentSearch.do?searchType=all&localDocTypesJson=7D&formAction=search&formInitialized=true&searchResultsView=default&btn_search=Search&docName=*<CLIPBOARD>*&wildcards=on&docRevision=&latestRevOnly=true&docProjectNumber=&docEngChangeOrder=&docLocation=&findLimit=500&docTypes=Customer+Drawing&docTypes=Production+Drawing&docTypes=Manufacturing+Process+Document&docTypes=Specification+Or+Standard
Note: replaced text with "CLIPBOARD" for clarification.
I was wondering if that's a type of "URL-programming" or how can I make a direct URL that prompts for the search results from the website? is that Javascript? or how is that programmed? (I know Swift and some Java, but have never really used Javascript).
It doesn't seem like you are asking an AutoHotKey (AHK) question, but to give you an AHK example you can copy, here is how I would use AHK to use Google.com to search for whatever is in my clipboard:
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate("https://www.google.com/search?q=" . StrReplace(Clipboard, " ", "+") . "", "")
Note, the URL format includes the query ("?q=whatever+you+had+in+Clipboard") in it with spaces replaced by "+"s.
Hth,

Imacros - Extract and select multiple items from selector via predefined variable

I'm trying to EXTRACT some content from a table to be used for selecting items on a select multiple box.
This works fine:
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple
FRAME NAME="iframeResult"
TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%volvo:%opel
How come that when creating the extract content as a variable, then it does not work:
The variable called SET CARS volvo:%opel
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple
FRAME NAME="iframeResult"
SET CARS volvo:%opel
TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%{{CARS}}
Error message:
Entry [volvo:%opel] not available [Box has 4 entries], line: 6 (Error code: -924)
In addition I can suggest another way:
' ... '
FRAME NAME="iframeResult"
SET CARS "volvo,opel"
EVENT TYPE=CLICK XPATH=EVAL("'//HTML/BODY/FORM/SELECT/OPTION[#value=\\'' + '{{CARS}}'.split(',')[0] + '\\']';") BUTTON=0 MODIFIERS="ctrl"
EVENT TYPE=CLICK XPATH=EVAL("'//HTML/BODY/FORM/SELECT/OPTION[#value=\\'' + '{{CARS}}'.split(',')[1] + '\\']';") BUTTON=0 MODIFIERS="ctrl"
According to the wiki documentation you have to write the code like this:
' ... '
FRAME NAME="iframeResult"
SET CAR1 "volvo"
SET CAR2 "opel"
TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%{{CAR1}}:%{{CAR2}}
Found a way using the script interface. Simply add the list of items to select usign JS:
function createMultiSelector(list) {
macro = "CODE:";
macro += "URL GOTO=https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple\n";
macro += "FRAME = 'iframeResult'\n";
macro += "TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%"+list+"\n";
iret = iimPlay(macro);
}

Show local image in WebView

I'm successfully using the WebView control to render a HTML string that I'm parsing to it... It's rendering my CSS, H1, and paragraph content perfectly.
Then, I tried to add an image tag and load in an image that is already stored locally on the phone. But it can't see to find or render the image in the WebView. How do I display locally stored images in the WebView?
Here's what I have tried:
string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string localFilename = "project-" + ProjectId + ".png";
string localPath = "file://" + Path.Combine(documentsPath, localFilename);
string FinalHtml =
"<html><head><style>a, h1 {color:#6fb731;} h1{font-size: 1.4em;} p, body{color:#333333;}</style></head><body>" +
"<img src=\"" + localPath + "\" />" +
"<h1>" + ProjectName + "</h1>" + ProjectHtml +
"</body></html>";
ProjectsWebView.LoadData(FinalHtml, "text/html", "UTF-8");

Getting Links from a HTML Page

I want to automate a Process at work. I have a web page which will have some 20-30 Links which starts with the specific words as follows.
abc1234
abc5142
abc9862
abc3621
Each of these lines are basically Links. Clicking on which I will get one more browser which will have the IP.
Now I want to know the IP behind each machine name (ex: abc6901) and I want to connect to those machines using VNC viewer.
Dim Browser, strOut
Set Browser = CreateObject("InternetExplorer.Application")
With Browser
.Visible = False
.Navigate "http://anees.amoeba.co.in/table.html"
'Wait for Browser
Do While .Busy
WScript.Sleep 100
Loop
End With
But when I tried to do the same, I failed to get the link details from the HTML page, using the .vbs script file. I worked on getting the same and found I'm stuck with the methods document.getElementById and some other methods which will get the link details.
Also, I don't know how to get the info of the node where these Links are present on the web page. For better understanding, I will be pasting my screen shot of my page from the application.
The Internet Explorer 5 Power Toys include a List Links program.
Create following htm page C:\Windows\WEB\urllist.htm
<script language=javascript defer>
var str = new String ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes, top=0, left=0, width=400, height=");
str = str + (screen.height - 100);
//alert (screen.height);
var dlProgress = window.open ("", "linkdownloader", str);
dlProgress.document.open();
dlProgress.document.writeln ("<html>");
dlProgress.document.writeln ("<head>");
dlProgress.document.writeln ("<title>Links list</title>");
dlProgress.document.writeln ("</head>");
dlProgress.document.writeln ("<body topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>");
dlProgress.document.writeln ("<font style=\"font: 8pt Verdana, Arial, Helvetica, Sans-serif; line-height:18pt;\">");
dlProgress.document.writeln ("<script language=javascript>function navigateClose(str){if (document.my_parent != null){document.my_parent.location.href=str;window.close();}else{alert(\"Please wait until the list has populated.\");}}<\/script>");
dlProgress.document.writeln (" List of all links in <b>" + external.menuArguments.document.title + "</b>:<ol>");
var links = external.menuArguments.document.links;
for (i = 0; i < links.length; i++)
{
if ( links(i).innerText != "" && links(i).innerText != " ")
{
dlProgress.document.writeln ("<li>" + links(i).innerText + "<BR>");
}
else
{
dlProgress.document.writeln ("<li><A HREF='javascript:navigateClose(\"" + links(i).href + "\")'>" + links(i).href + "</a><BR>");
}
}
dlProgress.document.writeln ("</ol><center>close</center><BR></body>");
dlProgress.document.writeln ("</font></html>");
dlProgress.document.close();
dlProgress.document.my_parent = external.menuArguments;
</script>
To install run this reg file.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\MenuExt\&Links List]
#="C:\\Windows\\WEB\\urllist.htm"
"contexts"=hex:01
To use right click page and choose Links List.

GWT html object show text as url or img

I get a URL as text from database and put it into an HTML object and add this object to layout.
I want this text to work as URL or IMG.
you can see in the code what I have tried. didn't find a method that does that...
my code :
int listSize = result.size();
int i;
assetPanel.clear();
for(i=0;i<listSize;i++)
{
HorizontalPanel vPanelPic = new HorizontalPanel();
HTML picSpace = new HTML();
picSpace.setHTML("<img src = " + result.get(i).getUrl() + "style=width:304px;height:228px>");
//Window.alert("<a href " + result.get(i).getUrl()+ "</a>");
vPanelPic.add(picSpace);
assetPanel.add(vPanelPic);
}
Your HTML is invalid. Try this:
// img:
picSpace.setHTML("<img src='" + result.get(i).getUrl() + "' style='width:304px;height:228px'>");
// link:
Window.alert("<a href='" + result.get(i).getUrl() + "'>URL</a>");
I think that post solves the problem without any security issues :
For SafeHtml, Do we need to sanitize the "link" in <img src=link> tag, GWT?