I want to get documents/spreadsheets/presentations alone from drive.I used search query q parameter to get documents based on mimeType, but using this I can able to get only one particular mimetype files.Drive supports two mimetypes for spreadsheets
1.application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
2.application/x-vnd.oasis.opendocument.spreadsheet
There is no or operator to form a query.Can anyone help me to get a solution for this?
There is an OR operator. Use mimeType = 'application/vnd.google-apps.spreadsheet' or mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' to query your files.
Related
I am trying to scrape data from wine-searcher.com and am having an issue with IMPORTXML in google sheets, I keep getting the "could not fetch url" error when trying either of the following:
=IMPORTXML("https://www.wine-searcher.com/find/robert+mondavi+rsrv+cab+sauv+napa+valley+county+north+coast+california+usa","//h1")
=IMPORTXML("https://www.wine-searcher.com/find/robert+mondavi+rsrv+cab+sauv+napa+valley+county+north+coast+california+usa","//*[#id='tab-info']/div/div[1]/div[2]/div/div[1]/span[2]/span[2]") ( xpath to scrape current average price)
I've tried suggestions in other stack posts such as with/out http/s, www, and both XPath and full XPath to no avail. I have also tried with other URLs and they work no problem, maybe the problem is with URL length or format? Any help would be appreciated. If it cannot be done with IMPORT XML, any free alternatives suggested?
As the page is built in javascript on the client side and not on the server side, you will not be able to retrieve the data by the importxml / importhtml functions. However, the page contains a json which you can retrieve and analyze to retrieve the information you need.
function myFunction() {
var url = 'https://www.wine-searcher.com/find/robert+mondavi+rsrv+cab+sauv+napa+valley+county+north+coast+california+usa'
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.split('<script type="application/ld+json">')[1].split('</script>')[0]
var data = JSON.parse(jsonString)
Logger.log(data)
}
all these informations are available, from x=0 to x=23
data.offers[x].#type
data.offers[x].priceCurrency
data.offers[x].availability
data.offers[x].priceValidUntil
data.offers[x].url
data.offers[x].name
data.offers[x].seller.#type
data.offers[x].seller.name
data.offers[x].seller.description
data.offers[x].seller.availableDeliveryMethod
data.offers[x].seller.address.#type
data.offers[x].seller.address.addressRegion
data.offers[x].seller.address.addressCountry.#type
data.offers[x].seller.address.addressCountry.name
data.offers[x].priceSpecification.#type
data.offers[x].priceSpecification.description
data.offers[x].priceSpecification.price
data.offers[x].priceSpecification.priceCurrency
https://docs.google.com/spreadsheets/d/17f6lhaHA_xpSWClzxkYZcNs4FeM4VHA480QrmwyJvT4/copy
as mentioned both these basic formulae return nothing:
=IMPORTXML("https://www.wine-searcher.com/find/robert+mondavi+rsrv+cab+sauv+napa+valley+county+north+coast+california+usa"; "//*")
=IMPORTDATA("https://www.wine-searcher.com/find/robert+mondavi+rsrv+cab+sauv+napa+valley+county+north+coast+california+usa")
pls note that importing data into spreadsheet is URL specific, so if something works well for www.aaa.org most likely it wont work for www.bbb.org
The query string in try it section does not work 12 hours ago.
My query string is mimeType = 'application/vnd.google-apps.folder'
Anyway not work with any query.
https://developers.google.com/drive/v2/reference/children/list
Please tellme why??
I'm having the same issue:
child.Q = "mimeType = 'application/vnd.google-apps.folder' and title contains 'SomeDocuments'"
Dim cl As ChildList = child.Fetch
it returns all the documents like there was no filter
Maybe something change on Google Drive API?
Update
I can't find anything from Google, I wrote a feedback in the child list page.
The only workaround so far is instead of using the children.list use the file.list method and in the q section add the - 'folderid' in parents - search term to emulate searching on childrens of the parent folder.
The drawback is it will only search for document that has folderid as parent, not sub-folders like children.list method do.
Update 2
Looks like Google fixed it!
Happy coding.
Following the doc https://developers.google.com/drive/search-parameters on search parameters, I can combine parameters with and. mimeType-s can be tested with =. Can I extract multiple mime types files in one query? No or operator in the doc or if I can use contains for mimeType.
I feel it's worth noting that demi's last comment is correct I was able to specify a subset of mimtypes as follows:
(mimeType = 'application/vnd.google-apps.folder' or
mimeType = 'application/vnd.google-apps.file' or
mimeType = 'application/vnd.google-apps.spreadsheet')
Hope that helps anyone else looking at this question in the future as it is not clear in the documentation.
There is no or operator for now. However, you can use batch call for Drive API to achieve same goal. This will merge multiple queries into one.
UPDATE: Please refer to Luke's comment below.
You can list all the files and folders by adding this (mimeType contains 'application/vnd.google-apps.document' or mimeType contains 'application/vnd.google-apps.folder') in q parameter.
Your URL will be looks like this -
https://www.googleapis.com/drive/v3/files?q=(mimeType%20contains%20%27application%2Fvnd.google-apps.document%27%20or%20mimeType%20contains%20%27application%2Fvnd.google-apps.folder%27)
https://www.googleapis.com/drive/v3/files?key=YOUR_GOOGLE_API_KEY&q=(mimeType='application/pdf' or mimeType='image/png') and trashed = false and 'GOOGLE_DRIVE_FOLDER_ID' in parents
Is there a way to list only files with a particular extension?
I tried "title contains '.mm'" but this returns no results, although there is a file like that in Drive. I also tried "mimeType = 'application/vnd.google.drive.ext-type.mm', no luck as well.
You should use:
fileExtension = 'mm'
I have successfully used the information in the link below to get a JSON output from a Google spreadsheet.
https://developers.google.com/gdata/samples/spreadsheet_sample
Is it possible to combine this JSON request with a data query, such as those seen in the link below this?
https://developers.google.com/chart/interactive/docs/querylanguage
Yes. Use the new url for accessing google docs:
https://docs.google.com/spreadsheets/d/%KEY%/gviz/tq?gid=%GID%&tq=%QUERY%
%KEY% and %GID% can be found in your spreadsheet's url, and %QUERY% is whatever you are asking the sheet for. For example, you might ask it to look up a phone number in column B by looking for a name in column A by passing "B where A = 'John Smith'" as the %QUERY%.
seems like it doesn't need the GID parameter :D