I am trying to create a chrome extension that will save your google search inputs in a CSV file that is downloadable. For example: I enter the search input in google search "programming python tutorials". When search input is typed, I should be able to click the action button chrome extension to save the search input in an organized CSV file that is downloadable. This is similar to web scraping, but not really. I don't want the website information saved, I just want the search inputs saved. I have searched the chrome extension web store and online tutorials, but really haven't found anything on this. Can you please suggest where I can get started? Thank you.
Asked
Active
Viewed 1,023 times
2 Answers
0
What you want is a content script that is run only on Google search. eg
{
"name": "Log Google",
"version": "1.0",
"description": "Log Google search data",
"permissions": ["tabs", "*://*.google.com/*"],
"content_scripts": [
{
"matches": ["*://*.google.com/*"],
"js": ["logdata.js"]
}
]
}
Where logdata.js
is the code that you want to run whenever you visit the search page. I would suggest parsing the url of the page and getting the query rather than sorting through html elements.
To get the url of the current tab:
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
});
As for writing to the disk, take a look at the chrome.fileSystem api.
Hope this helps.

IeuanG
- 504
- 5
- 13
0
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('checkPage');
checkPageButton.addEventListener('click', function() {
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
}, false);
}, false);
//logdata.js
{
"manifest_version": 2,
"name": "Log Google",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"description": "Log Google search data",
"permissions": ["tabs", "*://*.google.com/*"],
"content_scripts": [
{
"matches": ["*://*.google.com/*"],
"js": ["logdata.js"]
}
]
}
//manifest.json
<!doctype html>
<html>
<head>
<title>Open Log</title>
<script src="logdata.js"></script>
</head>
<body>
<h1>Logger</h1>
<button id="checkPage">Results</button>
</body>
</html>
popup.html

user3692559
- 1
- 1
-
This is what I have. Any suggestion on what I can do to get the correct results? – user3692559 Mar 13 '16 at 19:06
Logger
– user3692559 Mar 13 '16 at 18:54