I want to extract data from the Google keyword tool - https://adwords.google.com/select/KeywordToolExternal. Their site is in Javascript, the script I've been working on is in PHP. Anyway to do this?
Alternatively, if there is no good solution, I was thinking of downloading the csv file and extracting data from it. Unfortunately, I've never done something where I download a csv file then extracted data from it. Can anyone point me in the right direction?
Scraping the Keyword tool is not easy (and it breaks the terms and conditions).
If you download the CSV file you can read it with php (it is a plain text file). You will have to create the logic to use the data in the file.
this will get you started
$file_handle = fopen("myfile", "r");
while (!feof($file_handle)) {
$line = fgets($file_handle);
echo $line;
}
fclose($file_handle);
Related
I would like to retrieve data from specific cells in a local Excel sheet using Javascript and then output it on an HTML page. My function would be something like readData(row, col).
For example:
Cell 1A = "hello"
<h4><script>readData(1, A)</script></h4> will show as "hello" on my page.
Every solution I have seen has involved uploading the file first (example below from the read-excel-file package), but my Excel file is already a local file within my project.
<script>
var input = document.getElementById('input')
input.addEventListener('change', function() {
readXlsxFile(input.files[0]).then(function(rows) {
// `rows` is an array of rows
// each row being an array of cells.
})
})
</script>
My guess is you are referring to this project?
https://gitlab.com/catamphetamine/read-excel-file
I tried using the Node.js example. It works out of the box. The examples for a direct website integration are broken. The project seems still alive, but I would scan the code to decide if to trust the author with your data.
Here how to fix the example (I have no idea for what cases it works!):
Go into the "website" folder. The index.html is a example how to use it. Unfortunately the "read-excel-file.min.js" is missing in the repo. You can download it here (view-source:https://catamphetamine.gitlab.io/read-excel-file/read-excel-file.min.js). Put it in the folder and it works.
Maybe someone has a better code for this?
EDIT (Above answer not technically wrong but does not answer the post):
What you want is not possible to security reasons! Just imagine your javascript (client!) code:
inputfile="test.xlsx"
I could edit this in my browser to
inputfile="super_secret_files_on_server.xlsx"
Solution: You could run node.js code on your server and solve it this way, or the user has manually upload a file from his computer. Or use a server side programming languages like php.
I have a D3 graph which reads a JSON file. Where I am struggling is, what is the mechanism to get the dynamically generated PHP JSON data into the D3 graph.
I think the obvious solution from someone like myself with limited knowledge would be to have PHP write a JSON file to a directory on load, and then have the D3 graph look for it.
However, I feel like there is a better way to do it without writing a json file and reading a json file.
Could anyone please suggest the industry standard method for something like this, so I can continue my reading.
Just request the PHP script from D3 like it is a JSON file. Then in your PHP script...
$data = array('your', 'data', 'here');
header('Content-Type: application/json');
echo json_encode($data);
exit();
I have a .json file in the same directory as my html file. I want to access this file and modify it. This modified file data will be used to load the contents of the same html file.
How can I access the file and modify it in Javascript?
Being a newbie in Javascript, any help is appreciated.
Thanks.
HTML5 added a file api for interacting with files on your computer.
This HTML5Rocks article explains how to use it.
this MDN page also explains it
html
<input type="file" id="input" multiple onchange="handleFiles(this.files)">
js
var inputElement = document.getElementById("input");
inputElement.addEventListener("change", handleFiles, false);
function handleFiles() {
var fileList = this.files; /* now you can work with the file list */
}
api link:
FileReader.readAsText()
You cannot do this solely with HTML and javascript. What you want to do requires reading the file on the web server, not from the user's hard drive. Therefore, you must use a back-end language, like PHP. It's actually pretty easy.
If you haven't used PHP before, you can test that you have access to it (almost everyone does except those on Microsoft OS web servers). Just create a new file called test.php and make it look like this:
<?php
echo 'Hello there';
Then, navigate to http://whatever_your_domain_is/test.php
To access your JSON document, you can either do it as the page is loading, as follows:
(1) Rename the page from .html to .php -- all this does is allow PHP to be processed on the page. Otherwise, it is exactly the same as an HTML page.
(2) Add a section like this at the top:
<?php
$filePath = "json_file_name.txt";
$handle = fopen($filePath, "r");
$json = fread($handle, filesize($filePath));
?>
(3) Later, in your javascript code, plop that into a variable, like this:
$(function(){
var imported = "<?php echo $json; ?>";
var json = $.parseJSON(imported); //or, JSON.parse(imported);
}); //END document.ready
Or, you can use AJAX to do it on demand (i.e., triggered by a user event, such as a button click).
Here are some examples that demonstrate how easy AJAX is.
Note that using AJAX will not allow you to avoid the back-end server language (PHP). AJAX code communicates with a back-end (PHP) file, which does the same work as that described in the above section, and sends the result back to the AJAX success function in the javascript. The advantage of AJAX is being able to do it on demand, instead of just when the page is initially rendered.
Other refs:
how to parse json data with jquery / javascript?
We're a group of guys working on a bachelor project for a consultant firm that wants an easy step by step webpage/program for analysing numbers for consultant purposes. We want to make this cross-browser compatible, but looking across the internet it seems like the only way it will work is with IE and its "safe" ActiveX function.
Most of the answers we've found involves, as far as I know, real time updates/refreshing of the excel spreadsheet, therefore the need for ActiveX? This is not exactly what we are looking for.
The excel spreadsheet we are looking to import looks the same every time, but with different data on it and will be fetched by the page manually when needed, which is why we just want a simple browse file button on the page, fetching the spreadsheet and neatly positioning the numbers required into fields on the page.
Is there no way to do this with JavaScript or PHP without using:
ActiveXObject ?
Edited : 30'th of October.
We've looked into the PHPExcel library, started working on it, but getting this error when just trying to locate the file we want to read.
Fatal error: Class 'PHPExcel_Reader_C:/SKOLE/test/Excelrapporter/Balanse.xls' not found in C:\Programmer\XAMPP\htdocs\phpexcel\Classes\PHPExcel\IOFactory.php on line 170
Here is the current code for just trying to read the file:
<?php
$data = "";
/*require_once("bachelor/classes/phpexcel/IOFactory.php");*/
require_once 'C:/Programmer/XAMPP/htdocs/phpexcel/Classes/PHPExcel/IOFactory.php';
$filename = 'C:/SKOLE/test/Excelrapporter/Balanse.xls';
try{
$inputFileType = PHPExcel_IOFactory::identify($filename);
$objReader = PHPExcel_IOFactory::createReader($filename);
$objPHPExcel = $objReader->load($filename);
}catch(Exception $e) {
die('Error loading file "'.pathinfo($filename,PATHINFO_BASENAME).'": '.$e->getMessage());
}
?>
When going through tutorials on this online, we were told to put PHPExcel into the Xampp/htdoc directory, which we have done. This is why we have included 2 seperate complete paths to both the IOFactory.php and the excel file we want to read.
Any help on what we are doing wrong would be greatly apprechiated.
I'm having a problem when sending large amounts of data through an AJAX request. I'm pulling in an XLS file from a website and attempting to pass it through an API by parsing the data. I'm doing this in VBScript/Classic ASP so there is no native function to parse XLS so I'm first attempting to convert it to a CSV file through Javascript.
I'm using something called SheetJS (http://oss.sheetjs.com/js-xls/) which is a great tool and it works just as I need it to. I can run an Excel file through it and it outputs the correct CSV data. I then try to send that data via AJAX to the ASP page with my code and I get a 500 error that I've isolated to being an issue with the file being too large. I was able to isolate to about 1652 lines of my Excel file and anything past that generates a CSV file too large to send.
All I am getting is a 500 error so I'm not really sure what else to do from this point. Is there a data limit on AJAX functions? Or is it a time limit type issue? I don't know how to find out which it is. Any suggestions on how to get a more detailed error message AND any fixes for this issue?
While you can't work with .xls files natively in VBScript, there is ADO that makes it easy to do that via COM. This way scales well wrt memory. Start your research here.