I have a bunch of links to google maps in the form of https://maps.google.com/?cid=<identifier>.
How can you go from that CID to a Place ID that can be used with the Google Places API? Is there any API endpoint that you can use to convert these URLs into the new places?
Got lucky and found an undocumented api. If you have the CID, you can call the api like https://maps.googleapis.com/maps/api/place/details/json?cid=${CID}&key=YOUR_API_KEY.
I just changed place_id=${the_end_val_i_needed} to cid=${CID} and in the json response is the place_id.
You can use this API hidden parameter to get Place ID. Usage: https://maps.googleapis.com/maps/api/place/details/json?cid=YOUR_CID&key=YOUR_KEY
It returns a result contains formatted address, place_id, name of the address and GPS coordinater.
Please see my blog to see more detail: https://leonbbs.blogspot.com/2018/03/google-map-cid-to-placeid-or-get.html
The only way that I am aware of is scraping the regular html response. This can change of course at any time at Googles discretion and I would be interested in a better solution as well.
As of now e.g. the source of http://maps.google.com/?cid=15792901685599310349 has a json response embedded. It starts with cacheResponse([[[ and ends with ]);:
<!DOCTYPE html>
<html dir=ltr>
<head>
<script nonce="W6BFnVsL4HLAdFCwYXZY">
mapslite = {
START_PERF: (window.performance && window.performance.now) ?
window.performance.now() : +(new Date())
};
mapslite.getBasePageResponse = function(cacheResponse) {
delete mapslite.getBasePageResponse;
cacheResponse([[[2556.225486744883,-122.3492774,47.6205063], ... removed ... ]);
};
executeOgJs = function() {
Within this json array element 8 contains a sub array. Element 27 is the place_id.
In case of the Space Needle with CID 15792901685599310349 the place id is ChIJ-bfVTh8VkFQRDZLQnmioK9s.
Only Google knows why they don't provide a better way.
Related
I'm trying to scrape the number of posts to a given hashtag (#castles) and populate a Google Sheet cell using ImportXML.
I tried copying the Xpath from Chrome and paste it to the ImportXML parameter in the cell like this:
=ImportXML("https://www.instagram.com/explore/tags/castels/", "//*[#id="react-root"]/section/main/header/div[2]/div/div[2]/span/span")
I saw there is a problem with the quotation marks so I also tried:
=ImportXML("https://www.instagram.com/explore/tags/castels/", "//*[#id='react-root']/section/main/header/div[2]/div/div[2]/span/span")
Nevertheless, both return an error.
What am I doing wrong?
P.S. I am aware of the Xpath to the meta tag description "//meta[#name='description']/#content" however I would like to scrape the exact number of posts and not an abbreviated number.
Try this -
function hashCount() {
var url = 'instagram.com/explore/tags/cats/';
var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true}).getContentText();
var regex = /(edge_hashtag_to_media":{"count":)(\d+)(,"page_info":)/gm;
var count = regex.exec(response)[2];
Logger.log(count);
}
Demo -
I've added muteHttpExceptions: true which was not added in my comment above. Hope this helps.
To get information about a word in Wiktionary, I can make an Ajax call to the following URL at wiktionary.org: https://en.wiktionary.org/w/api.php?action=parse&format=json&prop=text|revid&callback=?&page=слово, where слово is the word of interest.
This will return a JSON object with the format...
{ "parse":
{ "title": "\u0442\u044b"
, "pageid":96216
, "revid":38162039
, "text":{
"*": <HTML string>
}
}
}
... where <HTML string> contains information on the given word, in all the languages that Wiktionary associates with the word. In the case of the word слово, this means
Bulgarian
Macedonian
Old Church Slavonic
Russian
Serbo-Croatian
Ukrainian
How can I change the URL for the Ajax call so that it only returns data for a single language (for example: Russian)?
It's not possible as in terms of Wiktionary each word is a page with wiki-formatted text. It's not structured as a JSON or any other machine readable data structure format. Though, they have a convention which every page is supposed to follow. According to it, each page should have level 2 headings with word's language. So, you can parse the wikitext to extract only the data for the language you want by looking for such a heading and taking only the data below it.
I need to send emails out to several thousand customers with a unique barcode present so they can redeem it either instore or online.
We have a list of coupon/barcode codes to use and have a way to dynamically pull these codes into the email so a customer will see a unique code. The problem is I need to somehow generate several thousand barcode images that are created using the unique codes. How can I solve this?
This would be perfect if our email marketing company had this functionality but unfortunately they don't:
http://www.emaildirect.com/blog/2011/11/create-unique-barcodes-with-emaildirect/
Any help would be greatly appreciated.
I have found my answer!
By using the barcode generator www.barcodesinc.com I generated a URL and input this into my email.
Eg: http://www.barcodesinc.com/generator/image.php?code=999999999&style=197&type=C128B&width=200&height=50&xres=1&font=3
I then changed the 999999999 in the URL to my conditional code to change to the specific code for that person and also bring back the barcode image for that code too!
I have found my answer!
By using the barcode generator www.barcodesinc.com I generated a URL and input this into my email.
Eg: http://www.barcodesinc.com/generator/image.php?code=999999999&style=197&type=C128B&width=200&height=50&xres=1&font=3
I then changed the 999999999 in the URL to my conditional code to change to the specific code for that person and also bring back the barcode image for that code too!
<img src="http://qrfree.kaywa.com/?s=8&d=your+text+here" alt="QRCode"/>
OR
http://qrfree.kaywa.com/?s=8&d=your+text+here
I'm no expert on this and haven't touched html but you could serialize each image and follow this example that has some sample code on QR code given a string.
Imports ThoughtWorks.QRCode.Codec
Dim objQRCode As QRCodeEncoder = New QRCodeEncoder()
Dim imgImage As Image
Dim objBitmap As Bitmap
objQRCode.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE
objQRCode.QRCodeScale = 2
objQRCode.QRCodeVersion = 5
objQRCode.QRCodeErrorCorrect = ThoughtWorks.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.L
imgImage = objQRCode.Encode("Test Data")
objBitmap = New Bitmap(imgImage)
objBitmap.Save("C:\QRCode.jpg")
Hi Try getting in touch with http://www.linktagger.com and ask if they can help. They provide Enterprise type services for the city where I live on maps and bus terminals so it might help you.
Here is an working example to generate barcode for the array of barcodes.We can
retrieve thousands of barcodes from csv file using pandas as well.
This example calls API and save the response in image(.png format) obtained as response from API call.
import shutil
import requests
data = [11111111111, 22222222222222222, 33333333333333, 4444444444444]
url = 'https://www.barcodesinc.com/generator_files/' + 'image.php?'
for d in data:
params = {
'code': d,
'style': '197',
'type': 'C128B',
'width': '200',
'height': '50',
'xres': '1',
'font': '3',
}
response = requests.get(url, params, stream=True)
with open('image-%s.png' % d, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
Im using php and magpie and would like a general way of detecting images in feed item. I know some websites place images within the enclosure tag, others like this images[rss] and some simply add it to description. Is there any one with a general function for detecting if rss item has image and extracting image url after its been parsed by magpie?
i think reqular expressions would be needed to extract from description but im a noob at those. Please help if you can.
I spent ages searching for a way of displaying images in RSS via Magpie myself, and in the end I had to examine the code to figure out how to get it to work.
Like you say, the reason Magpie doesn't pick up images in the element is because they are specified using the 'enclosure' tag, which is an empty tag where the information is in the attributes, e.g.
<enclosure url="http://www.mysite.com/myphoto.jpg" length="14478" type="image/jpeg" />
As a hack to get it to work quickly for me I added the following lines of code into rss_parse.inc:
function feed_start_element($p, $element, &$attrs) {
...
if ( $el == 'channel' )
{
$this->inchannel = true;
}
...
// START EDIT - add this elseif condition to the if ($el=xxx) statement.
// Checks if element is enclosure tag, and if so store the attribute values
elseif ($el == 'enclosure' ) {
if ( isset($attrs['url']) ) {
$this->current_item['enclosure_url'] = $attrs['url'];
$this->current_item['enclosure_type'] = $attrs['type'];
$this->current_item['enclosure_length'] = $attrs['length'];
}
}
// END EDIT
...
}
The url to the image is in $myRSSitem['enclosure_url'] and the size is in $myRSSitem['enclosure_length'].
Note that enclosure tags can refer to many types of media, so first check if the type is actually an image by checking $myRSSitem['enclosure_type'].
Maybe someone else has a better suggestion and I'm sure this could be done more elegantly to pick up attributes from other empty tags, but I needed a v quick fix (deadline pressures) but I hope this might help someone else in difficulty!
I want to make an AJAX call to an HTML-returning page, extract part of the HTML (using jQuery selectors), and then use that part in my jQuery-based JavaScript.
The AJAX retrieval is pretty simple. This gives me the entire HTML document in the "data" parameter of the callback function.
What I don't understand is how to handle that data in a useful way. I'd like to wrap it in a new jQuery object and then use a selector (via find() I believe) to get just the part I want. Once I have that I'll be passing it off to another JavaScript object for insertion into my document. (This delegation is why I'm not using jQuery.load() in the first place).
The get() examples I see all seem to be variations on this:
$('.result').html(data);
...which, if I understand it correctly, inserts the entire returned document into the selected element. Not only is that suspicious (doesn't this insert the <head> etc?) but it's too coarse for what I want.
Suggestions on alternate ways to do this are most welcome.
You can use your standard selector syntax, and pass in the data as the context for the selector. The second parameter, data in this case, is our context.
$.post("getstuff.php", function(data){
var mainDiv = $("#mainDiv", data); // finds <div id='mainDiv'>...</div>
}, "html");
This is equivalent to doing:
$(data).find("#mainDiv");
Depending on how you're planning on using this, $.load() may be a better route to take, as it allows both a URL and a selector to filter the resulting data, which is passed directly into the element the method was called on:
$("#mylocaldiv").load("getstuff.php #mainDiv");
This would load the contents of <div id='mainDiv'>...</div> in getstuff.php into our local page element <div id='mylocaldiv'>...</div>.
You could create a div and then put the HTML in that, like this…
var div = $("<div>").html(data);
...and then filter the data like this…
var content = $("#content", div.get(0));
…and then use that.
This may look dangerous as you're creating an element and putting arbitrary HTML into it, but it's not: anything dangerous (like a script tag) will only be executed when it's inserted into the document. Here, we insert the data into an element, but that element is never put into the document; only if we insert content into the document would anything be inserted, and even then, only anything in content would be inserted.
You can use load on a new element, and pass that to a function:
function handle(element){
$(element).appendTo('body');
}
$(function(){
var div = $('<div/>');
div.load('/help a', function(){handle(div);});
});
Example: http://jsbin.com/ubeyu/2
You may want to look at the dataFilter() parameter of the $.ajax method. It lets you do operations on the results before they are passed out.
jQuery.ajax
You can do the thing this way
$.get(
url,
{
data : data
},
function (response) {
var page_content = $('.page-content',response).get(0);
console.log(page_content);
}
)
Here in the console.log you will see the inner HTML of the expected/desired portion from the response. Then you can use it as your wish