Possibly Encrypted "a href" Links at TripAdvisor - html

On TripAdvisor.com attraction pages, the link to the website of the attraction seems to be encrypted in some way. Here is an example:
<span class="taLnk hvrIE6" onclick="ta.trackEventOnPage('AttractionContactInfo',
'Website', 1755031, 1); ta.util.cookie.setPIDCookie(15190);
ta.call('ta.util.link.targetBlank', event, this
{'aHref':'LqMWJQiMnYQQoqnQQxGEcQQoqnQQbIIEJnISiCQQoqnQQeVsSVuWJQzZYUWJQpEcYGII26XombQQoqnQQQQoqnqgoqnQQQQoqnQQQQoqnQQQQoqnqgoqnQQQQoqnQQEVMIGVJIEV9pCyTptGiuQQoqnQQQQoqnxioqnQQQQoqnQQniaWJQzhY3mJnJUUJXomoAvoJJB', 'isAsdf':true})">
Website
</span>
How is this link made and what might be the reason for doing so?

The aHref value is an encrypted URL that can be decrypted using the TripAdvisor asdf() Javascript function. For example, using the Javascript console in Firefox, type the following while at www.tripadvisor.com:
console.log(asdf('encrypted URL'));
An example:
console.log(asdf('LqMWJQzZYUWJQpEcYGII26XombQQoqnQQQQoqnqgoqnQQQQoqnQQQQoqnQQQQoqnqgoqnQQQQoqnQQuuuQQoqnQQQQoqnxioqnQQQQoqnQQEitVuiiMqxQQoqnQQQQoqnxioqnQQQQoqnQQniaQQoqnQQQQoqnqgoqnQQQQoqnQQVCQQoqnQQQQoqnqgoqnQQQQoqnQQIGVQQoqnQQQQoqnqHoqnQQQQoqnQQnJEcgcVQQoqnQQQQoqnqHoqnQQQQoqnQQCVuQQoqnQQQQoqnqHoqnQQQQoqnQQgiE9QQoqnQQQQoqnqgoqnQQQQoqnQQMSCSCyQQoqnQQQQoqnqgoqnQQQQoqnQQHVaVcaJCtQQoqnQQQQoqnqHoqnQQQQoqnQQHJEWJQzhYUMo3JKHkmKnVmJVdUB'));
Gives the following (append to http://tripadvisor.com):
/ShowUrl-a_partnerKey.1-a_url.http%253A__5F____5F__2F__5F____5F____5F____5F__2F__5F____5F__www__5F____5F__2E__5F____5F__rosewoodhotels__5F____5F__2E__5F____5F__com__5F____5F__2F__5F____5F__en__5F____5F__2F__5F____5F__the__5F____5F__2D__5F____5F__carlyle__5F____5F__2D__5F____5F__new__5F____5F__2D__5F____5F__york__5F____5F__2F__5F____5F__dining__5F____5F__2F__5F____5F__bemelmans__5F____5F__2D__5F____5F__bar-a_urlKey.1d56a0b730ce3ae41.html
The source of the TripAdvisor asdf() function:
function asdf(d) {
var h = {
"": ["&", "=", "p", "6", "?", "H", "%", "B", ".com", "k", "9", ".html", "n", "M", "r", "www.", "h", "b", "t", "a", "0", "/", "d", "O", "j", "http://", "_", "L", "i", "f", "1", "e", "-", "2", ".", "N", "m", "A", "l", "4", "R", "C", "y", "S", "o", "+", "7", "I", "3", "c", "5", "u", 0, "T", "v", "s", "w", "8", "P", 0, "g", 0],
q: [0, "__3F__", 0, "Photos", 0, "https://", ".edu", "*", "Y", ">", 0, 0, 0, 0, 0, 0, "`", "__2D__", "X", "<", "slot", 0, "ShowUrl", "Owners", 0, "[", "q", 0, "MemberProfile", 0, "ShowUserReviews", '"', "Hotel", 0, 0, "Expedia", "Vacation", "Discount", 0, "UserReview", "Thumbnail", 0, "__2F__", "Inspiration", "V", "Map", ":", "#", 0, "F", "help", 0, 0, "Rental", 0, "Picture", 0, 0, 0, "hotels", 0, "ftp://"],
x: [0, 0, "J", 0, 0, "Z", 0, 0, 0, ";", 0, "Text", 0, "(", "x", "GenericAds", "U", 0, "careers", 0, 0, 0, "D", 0, "members", "Search", 0, 0, 0, "Post", 0, 0, 0, "Q", 0, "$", 0, "K", 0, "W", 0, "Reviews", 0, ",", "__2E__", 0, 0, 0, 0, 0, 0, 0, "{", "}", 0, "Cheap", ")", 0, 0, 0, "#", ".org"],
z: [0, "Hotels", 0, 0, "Icon", 0, 0, 0, 0, ".net", 0, 0, "z", 0, 0, "pages", 0, "geo", 0, 0, 0, "cnt", "~", 0, 0, "]", "|", 0, "tripadvisor", "Images", "BookingBuddy", 0, "Commerce", 0, 0, "partnerKey", 0, "area", 0, "Deals", "from", "\\", 0, "urlKey", 0, "'", 0, "WeatherUnderground", 0, "MemberSign", "Maps", 0, "matchID", "Packages", "E", "Amenities", "Travel", ".htm", 0, "!", "^", "G"]
};
var b = "";
for (var a = 0; a < d.length; a++) {
var j = d.charAt(a);
var f = j;
if (h[j] && a + 1 < d.length) {
a++;
f += d.charAt(a)
} else {
j = ""
}
var g = getOffset(d.charCodeAt(a));
if (g < 0 || typeof h[j][g] == "String") {
b += f
} else {
b += h[j][g]
}
}
return b}
And the source of the getOffset() function referred to from asdf():
function getOffset(a) {
if (a >= 97 && a <= 122) {
return a - 61
}
if (a >= 65 && a <= 90) {
return a - 55
}
if (a >= 48 && a <= 71) {
return a - 48
}
return -1}

It could possibly be done to prevent screen scrapers and robots from automatically generating traffic to other sites.
Some server side code generated this and it's used for tracking, statistics and setting some cookie values etc.
Trip advisor will be able to determine what links were clicked and also share this information with the attraction (i.e. 50 people accessed your website from the Trip Advisor website etc)
Hope it's useful

Related

Regex to pick values from specific json key

My json string:
{
"computed_at": "2022-11-29T08:21:47.904741+00:00",
"data":
{
"2022-11-07":
{
"steps":
[
{
"count": 1853,
"avg_time": null,
"avg_time_from_start": null,
"session_event": "start",
"goal": "start",
"step_label": "Came to Corporate",
"overall_conv_ratio": 1,
"step_conv_ratio": 1
},
{
"count": 741,
"avg_time": 25451,
"avg_time_from_start": 25451,
"time_buckets_from_prev":
{
"lower": 0,
"higher": 0,
"buckets":
[
720,
2,
3,
4,
3,
3,
3,
1,
0,
2,
0,
0,
0,
0,
0
]
},
"time_buckets_from_start":
{
"lower": 0,
"higher": 0,
"buckets":
[
720,
2,
3,
4,
3,
3,
3,
1,
0,
2,
0,
0,
0,
0,
0
]
},
"event": "Viewed Collection Page",
"goal": "Viewed Collection Page",
"step_label": "Viewed Collection Page",
"overall_conv_ratio": 0.39989206691851054,
"step_conv_ratio": 0.39989206691851054
},
{
"count": 174,
"avg_time": 53538,
"avg_time_from_start": 110700,
"time_buckets_from_prev":
{
"lower": 0,
"higher": 0,
"buckets":
[
163,
2,
1,
3,
0,
2,
1,
2,
0,
0,
0,
0,
0,
0,
0
]
},
"time_buckets_from_start":
{
"lower": 0,
"higher": 0,
"buckets":
[
151,
4,
2,
5,
1,
4,
3,
3,
0,
1,
0,
0,
0,
0,
0
]
},
"event": "Product Viewed",
"goal": "Product Viewed",
"step_label": "Product Viewed",
"overall_conv_ratio": 0.09390178089584458,
"step_conv_ratio": 0.23481781376518218
}
],
"analysis":
{
"completion": 174,
"starting_amount": 1853,
"steps": 3,
"worst": 2
}
}
},
"meta":
{
"dates":
[
"2022-11-07"
],
"property_values":
[],
"min_sampling_factor": 1,
"group_by_metadata":
[]
},
"min_sampling_factor": 1
}
I want to extract the values for these particular keys (each of which has 3 instances in the above json string):
count
step_conv_ratio
What is the correct regex so that I will get 1853, 741, 174 for count; and 1, 0.39989206691851054, 0.23481781376518218 for step_conv_ratio?
Unmarshalling this to a Go struct is not ideal, since it has dynamic json field name, so I cannot use a static struct with static json tag to unmarshal. Hence I'm thinking of using regex.
Consider the comments about unmarshalling. Else the regex you are looking for is:
`"count": ([0-9]+)|"step_conv_ratio": ([0-9.]+)`
then the number will be in the second or the third element of the slice that contains the matches (e.g. after FindAllStringSubmatch()) depending on it's a count or a step_conv_ratio.

Map letters from array if the condition is met REACT

I have a state like this one:
const [word, setWord] = useState([
{
letters: ["r", "e", "a", "c", "t"],
shows: [0, 0, 0, 0, 1],
},
]);
and I want to render a letter if shows[i] == 1, else I want to render "_".
How can I do this using map in react (or maybe some other way)? I mean something like this:
map((letter, show) => (
show == 1 ? letter : '_'
))
You can use .map():
const word = {
letters: ["r", "e", "a", "c", "t"],
shows: [0, 0, 0, 0, 1],
}
console.log(word.letters.map((l, i) => word.shows[i] === 0 ? "_" : l))
word, in the question, is an array. I would suggest that you make it an object unless that is really required.
You may try object destructuring also
const { letters, shows } = word[0]
console.log(letters.map((l, i) => (shows[i] == 1 ? l : '_')))
let words = [
{
letters: ["r", "e", "a", "c", "t"],
shows: [0, 0, 0, 0, 1],
},
{
letters: ["j", "a", "v", "a", "s", "c", "r", "i", "p", "t"],
shows: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
},
]
/* you can map the words */
words.map(word =>
console.log(word.letters.map((letter, index) =>
(word.shows[index] == 1 ? letter : "_")))

How to do arithmetic substraction of same identical key values between 2 json files and print it in output json file

I've 2 json files of with identical key fields on both the file. I would like to get your assistance to do arithmetic subtraction of values of same key field between 2 files and present in 3rd output file [ delta of two json files to output json file].
Also 1st and 2nd json files has n of array of indicies so we need to do this in loop to map the difference values in 3rd json output file.
Example:
1st Json file: file1.json
[
{
"name": "Rock",
"pri": 21,
"size": 502173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_current": 0,
"merges_total": 0,
"refresh_total": 0
},
{
"name": "Rock:config",
"pri": 21,
"size": 512173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_curr": 0,
"merges_tot": 0,
"refresh_tot": 0
}
]
2nd Json file: file1.json:
[
{
"name": "Rock",
"pri": 22,
"size": 602173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_current": 0,
"merges_total": 0,
"refresh_total": 0
},
{
"name": "Rock:config",
"pri": 31,
"size": 602173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_curr": 0,
"merges_tot": 0,
"refresh_tot": 0
}
]
Output json file: file3.json should look like below.
[
{
"name": "Rock",
"pri": 1,
"size": 100000,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_current": 0,
"merges_total": 0,
"refresh_total": 0
},
{
"name": "Rock:config",
"pri": 10,
"size": 90000,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_curr": 0,
"merges_tot": 0,
"refresh_tot": 0
}
]
please help me with the logic
This can be done as simple as u follow the following steps
Read the json object from 2 json files and save them as list of dictionaries
Loop through the list of dicts and perform your required manipulations
Save calculated output dicts to a new list
Write the resultant list to a new json file
the code is as follows,
import json
with open('file1.json') as f:
data1 = json.load(f)
with open('file2.json') as f:
data2 = json.load(f)
data = []
for i,j in zip(data1, data2):
x = {}
for m,n in zip(i.items(), j.items()):
# if m[0] != "name":
if m[0] == "pri" or m[0] == "size":
x[m[0]] = int(j[m[0]]) - int(i[m[0]])
else:
x[m[0]] = i[m[0]]
data.append(x)
with open('file3.json', 'w') as o:
json.dump(data, o)

Need to import JSON data to Simple html file

Is there a way to import some data from json file into html file.
In need to import some of these data to a html file,
for example "Descrizione" and "Listino1" in a simple div.
Following is my json file sample:
[
{
"OP": "save",
"DB_NAME": "plu",
"ID": "005045",
"Barcode": "",
"CodVeloce": 0,
"CodPv": 0,
"FlagCondiviso": 1,
"CodTaccuino": 0,
"Descrizione": "BICC. VINO BIANCO",
"Famiglia": "006",
"ScortaMinima": 0,
"Posizione": 181,
"Reparto": 2,
"CodImmagini": 0,
"Listino1":4.00,
"Listino2":4.00,
"Listino3":0.00,
"Listino4":0.00,
"Stampante": 0,
"Flag": 1,
"Offerta": 0,
"Colore": 19,
"UnitMis": "",
"CodFornitore": 0,
"CodArtFornitore": "",
"BarcodeConfezione": "",
"PezziXConfezione": 0,
"ForzaLavoro": 0,
"PesoUnitario":0.00,
"NumConfezioni": 0,
"DescrizAggiuntiva": "",
"OffertaAggiuntiva": 0,
"PrezzoConfezione":0.00,
"ColoreTac": 0,
"Scala": 0,
"DtVar": "2020/02/03"
},
Any help.
Thanks in advance

Getting valurs froM JSON objects that have the same object string name

I'm getting my JSON object from the RIOT games API. Here is part of the JSON I get back:
{
"modifyDate": 1431043986000,
"champions": [
{
"id": 110,
"stats": {
"totalDeathsPerSession": 9,
"totalSessionsPlayed": 1,
"totalDamageTaken": 16507,
"totalQuadraKills": 0,
"totalTripleKills": 0,
"totalMinionKills": 164,
"maxChampionsKilled": 2,
"totalDoubleKills": 0,
"totalPhysicalDamageDealt": 101747,
"totalChampionKills": 2,
"totalAssists": 2,
"mostChampionKillsPerSession": 2,
"totalDamageDealt": 105995,
"totalFirstBlood": 0,
"totalSessionsLost": 1,
"totalSessionsWon": 0,
"totalMagicDamageDealt": 4248,
"totalGoldEarned": 7932,
"totalPentaKills": 0,
"totalTurretsKilled": 0,
"mostSpellsCast": 0,
"maxNumDeaths": 9,
"totalUnrealKills": 0
}
},
{
"id": 113,
"stats": {
"totalDeathsPerSession": 6,
"totalSessionsPlayed": 1,
"totalDamageTaken": 39226,
"totalQuadraKills": 0,
"totalTripleKills": 0,
"totalMinionKills": 75,
"maxChampionsKilled": 5,
"totalDoubleKills": 1,
"totalPhysicalDamageDealt": 28711,
"totalChampionKills": 5,
"totalAssists": 8,
"mostChampionKillsPerSession": 5,
"totalDamageDealt": 177132,
"totalFirstBlood": 0,
"totalSessionsLost": 1,
"totalSessionsWon": 0,
"totalMagicDamageDealt": 120299,
"totalGoldEarned": 12544,
"totalPentaKills": 0,
"totalTurretsKilled": 1,
"mostSpellsCast": 0,
"maxNumDeaths": 6,
"totalUnrealKills": 0
}
},
and so on for all of the champions in the game (there are around 150). If I wanted to calculate the total win/loss ratio or percent, I would have to find the total of "totalSessionsLost" and "totalSessionsWon". How would I go about totaling all of the values for this?
Thanks
var total_win = 0,
total_lost = 0,
champions = yourjsonobj.champions;
for (var i = 0; i < champions.length; i++) {
total_win += champions[i].totalSessionsWon;
total_lost += champions[i].totalSessionsLost;
}