Simple question from a noob :). The line below is from a javascript im trying to understand. The script is fetching data from a csv file to build a table based on a price slider. This line is the url that makes the visitor go to a specific website (a button i a table cell). My question is: What kind of file is in the /links/ directory and what exactly does '+line[6]+' mean?
content+='<td><a href="http://www.exampel.com/links/'+line[6]+'"
In a browser, the url looks like this (example): http://www.exampel.com/links/comapanyA
Without the actual file, I don't think it is discernible what exact type of file it is.
But, I can answer the "what exactly does '+line[6]+' mean?":
The plus signs on either side are string concatenation. So you are adding the results of "line[6]" to the url string.
"line[6]" is an array, with the sixth element being called by the index number "6".
Related
I started a little personal project just for fun. I hope posting what I'm doing here doesn't break any of the local rules. If so, let me know and I'll take the question down. No need to flag me for anything
I'm trying to pull the background image URL of my chromium homepage. Just for reference, the URL is https://www.mystart.com/new-tab/newtab/ When going to this page, nice background images are loaded. I'm trying to grab those images for personal, not commercial, use.
What I've traced down is that the page listed above calls out to another similar page: https://www.mystart.com/new-tab/newtab/newtab/ Currently, on line #1622 through #1636, two significant lines read:
var fastload = JSON.parse(localStorage.getItem('FASTLOAD_WALLPAPER_557b2c52a6fde1413ac3a48a'))
...
var url = fastload.info.cache_url || fastload.info.data_uri || fastload.info.image;
The value returned in the url is the URL to the background image. If I drop into the Chromium console and use: console.log(url), I see the exact data I'm trying to scrape. I'm wondering how I do that through python, since the actual textValue of url is not seen.
I have looked all over to try to find the localStorage object definition with no luck. I'm pulling the page with result = requests.get("https://www.mystart.com/new-tab/newtab/newtab/"); and then looking through result.text. I've also tried using BeautifulSoup to parse through things, not that this is really any different, but still not getting the results I'm looking for.
Being that I'm a hobbyist coder, I feel like I'm missing something simple. I've searched for answers, but I must be using the wrong keywords. I'm finding a lot of answers for parsing the urls that can be read, but not from the contents of a variable.
if you look at the requests being made, there is JSON response with info for 350 images. image_id is used in the url, e.g.
https://gallery.mystartcdn.com/mystart/images/<image_id>.jpeg
so for id=154_david-wilson-moab:
https://gallery.mystartcdn.com/mystart/images/154_david-wilson-moab.jpeg
Parse the JSON and get url for all images.
Note: this is not an answer of your question, but it looks like XY problem - this solves the underlying problem of retrieving image urls.
I want to get the screenshots from PageSpeed Insights. Using the API, I used a code that i founded here : https://embed.plnkr.co/plunk/c7fAFx, but doesn't work.
please help me! I am learning to code.
Why doesn't the linked code work?
Well because it is ancient and attempting to use the version 1 Page Speed Insights API.
It is currently on version 5 so that is why it does not work, v1 no longer exists as a public API.
How to recreate the functionality of this App?
As you are learning to code I will lay out the steps for you and then you can research how to do each step and use that to learn.
I will warn you as a beginner there is a lot to learn here. However on the flip side if you manage to work out how to do the below you will have a good first project that has covered multiple areas of JS development.
As you have marked this "JavaScript" I have assumed you want to do this in the browser.
This is fine up until the point where you want to save the images as you will have to work out how to ZIP them which is probably the most difficult part.
I have highlighted the steps you need to learn / implement in bold
1. First call the API:
The current URL for Page Speed Insights API is:
https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://yoursite.com
Just change url=https://yoursite.com to any site you want to gather the images from.
For a small amount of requests a day you do not need to worry about an API key.
However if you do already have an API key just add &key=yourAPIKey to the end of the URL (replacing the yourAPIKey part obviously :-P).
You want to make an AJAX call to the API URL first.
2. Parse the response
Then when you get a response you are going to get a large JSON response.
You need to parse the JSON response and turn it into a JavaScript Object or Array you can work with.
3. Find the relevant parts
So once you have a JavaScript Object you can work with you are looking for "final-screenshot" and "screenshot-thumbnails".
These are located under "audits".
So for example if you parsed to an array called lighthouseResults you would be looking for lighthouseResults['audits']['final-screenshot'] or lighthouseResults['audits']['screenshot-thumbnails']
"final-screenshot" contains how the site looked after it was loaded, so if you just want that you want this element.
This contains an image that is base64 encoded (lighthouseResults['audits']['final-screenshot']['details']['data']).
"screenshot-thumbnails" is the part you want if you want the "filmstrip" of how the site loads over time. This contains a list of the thumbnails base64 encoded.
To access each of these you need to loop over each of the items located at lighthouseResults['audits']['screenshot-thumbnails']['details']['items'] and return the ['data'] part for each ['item']
Find the parts that you want and store them to a variable
4a. Decode the image(s)
Once you have the image(s) in a variable, you will have them as a base64 encoded string at the moment. You need to convert these into usable jpg images.
To do this you need to base64 decode each image.
For now I would just display them in the browser once they are decoded.
learn how to decode a base64 encoded image
4b. Alternative to decoding the image
As the images are base64 encoded they can be displayed directly in a browser without decoding first.
You can just add an image where the src your base64 image string you gathered in step 3.
If you just want to display the images this is much easier.
Add images to the screen and set the src to the base64 image string you have from step 3
Saving the images
Now you said in a comment you want to save the images. Although this can be done via JavaScript it is probably a little advanced for starting out.
If you want to save the images you really want to be doing that server side.
However if you do want to download the images (filmstrip) in the browser then you want to look into a zip utility such as jszip.js.
The beauty of this is they normally want you to convert the images to base64 first before zipping them, so it may not actually be that difficult!
I'm writing some html that links to a server to download a file. The location always remains the same, however, the file name gets updated.
Basically the link is like this:
http://www.somedomain.com/somedir/dir/filename_revA.pdf
The filename will often get revised ("filename_revB.pdf") for example. My goal would not having to change the html href code each time this happens.
TL;DR-- I want to be able to reference an url, ie: 'http://www.somedomain.com/somedir/dir/'
but not need the filename to fetch the file that is there after the last /.
Would RegEx (javascript) be best solution or a better method? Sorry if it's been asked I tried searching couldn't quite get what I wanted- requesting a URL WITHOUT the filename needed-while still fetching the actual file that's there. There's only one file that is there at all times, but perhaps to be safer using part of the name since only the last part changes?
edit- I don't have access to the server that hosts the file(s).
I'm having a file which contains a couple of space separated (or comma separated, it will be editable) serial-numbers (all unique).
Now through my Oracle APEX I get one serial-number. My goal is to check if this serial code which could be passed on to a parameter of obtained through $v('P#_SERIAL_ID') is equal to one of the serial-numbers in the file.
Is this even possible within Javascript? If so, is there an existing function/code to achieve my goal?
Stackoverflow questions that didn't help me but look alike:
Javascript-read-file-contents
C#-reading-and-editing-file
Java-string-comparison
You can do this without JavaScript. Import your file into Apex through an Data Load Wizard Page so you will have the content of your file into a table. This way you can compare your information through some kind of SQL validation.
If you don`t like the Data Load Wizard Page you can add a file browse item on a simple page that will take your file and save it as a blob into the database. From there you can again process the file and compare the values.
I got a list of about 1500 images with IDs from shutterstock and already tried this with VBA and macros. But I am not really into VBA, so maybe someone knows how to write this in JS?
I have CSV with the IDs and want to parse the website of shutterstock like
this (i got the id in the csv "2166847")
And for this example I want to get the author "W14A" from the website and save it to the next column of the CSV (next to the ID-Column).
Or just generate a new CSV...
I am already trying to code it, but maybe someone know a simple fast solution?