Parsing Youtube - Xpath to retrieve a Youtube Channel's Profile Picture and Description - xpath

I would like to import the profile picture of a number of Youtube Channels into a Google Sheets spreadsheet.
This is the information that I have been able to retrieve so far:
To retrieve the profile picture, I have used the following code using Social Blade's website:
=IMPORTXML(D2,"//img[#id='YouTubeUserTopInfoAvatar']")
However while it doesn't result in an erorr it doesn't retrieve the image from the src. Any idea how to make it work?
In regard to the description, I would like to use a code that can be consistently used using either the channel's id or Youtube's username. Other solutions that I have tried have allowed me to get a truncated description, not the full one.
Maybe there is a more cost-effective way of doing this task, but without much Javascript experience this is the easiest way I have found to retrieve the information. Ideally, I would like to find a solution that calls on the Youtube API and bypasses the 50-call limit.
Here's a sample Google Sheets template to work on a solution.

OK. I've edited your Google Sheet. You forgot the #src attribute for the image.
=IMAGE(IMPORTXML(E2;"//img[#id='YouTubeUserTopInfoAvatar']/#src"))
And I've added the XPath for the Youtube channel description (add "/about" at the end of the youtube channel links).
=IMPORTXML(C2,"//div[#class='about-description branded-page-box-padding']")
Note : You have to fix your "ChannelID" formula to extract the ID.

Related

Picking random photo from an Instagram account

I would like to retrieve a photo from a random post on my Instagram account and display it on my website.
I don't need to show any data or comments from the post, just the photo.
What would be the best and the simplest solution to achieve this?
Would it be possible without the Gaph API?
I tried the Graph API, without really going any further because I felt like it is excessive for what seems to me to be a fairly simple task.
Any idea?

How do I insert images into a Google Sheet in Python using gspread (or any other package)?

I need a way to insert an image into a specific cell in a specific Google Sheet. If there is any python package and/or slice of code that can accomplish this, please let me know. As far as I am aware Gspread does not have anything helpful.
You can simply insert an image from an URL with a formula like this:
'=image("https://drive.google.com/uc?export=view&id={}")'.format(file_id)
When you insert/upload the data be sure to choose USER_ENTERED for value input option. https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption
With gspred:
sheet_instance.insert_rows(rows, value_input_option='USER_ENTERED')
Overall to add image into Google Sheets can be accomplished with Python by first inserting the image file in Google Drive using the Google Drive API:
Here is how to insert it to google drive. - https://developers.google.com/drive/v2/reference/files/insert#examples,
and secondly linking to the image in Google Sheets with the Google Sheets API, Here is Google sheets API - https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#CellData
Note: Look under CellData

Using Google Sheets for web scraping. Need the correct xpath for IMPORTXML function

There is a google sheet containing a list of MPN's (manufacturer part numbers). Trying to scrape a site called wikiarms for the UPC Codes when I have the MPN for an item.
I have the correct formula for doing this on another site.
=IMPORTXML("http://gun.deals/search/apachesolr_search/"&B1,"//dd/a[../../dt[contains(text(),'UPC')]]|//dd/span[../../dt[contains(text(),'UPC')]]")
Trying to figure out what the correct xpath to complete this formula. Some videos I have watch said to open the page in Chrome and use inspector to select and copy the xpath to complete the importxml function. I tried this with no luck.
Sample
Visit https://www.wikiarms.com/guns?q=20071
In the table there is a button "available in 6 stores" click that to reveal the list. The UPC should be listed after the MPN.
If I copy the xpath in Chrome this is the result
/html/body/div[1]/div/div/div[2]/div/div/div[2]/div[2]/table/tbody/tr[2]/td[5]
=IMPORTXML("https://www.wikiarms.com/guns?q="&B2,"xpath here")
What do I have to add at the end of this formula to pull in the UPC code? I will be using this formula to pull in UPC code for about 1000 items.
Thank you for your help.
Using your sample link, try
=IMPORTXML("https://www.wikiarms.com/guns?q=20071","//td[#class='upc']/a/#title")
and see if it works for you.

YouTube Video Topics/Categories

I'm working with YouTube videos and I noticed the field topicDetails.topicCategories (see in the API). It's not clear to me if this field is autogenerated by YouTube or if the user has to fill it. I tried to find some relevant field when editing the video but I didn't find it anywhere. So I guess YouTube fills this field based on tags, keywords etc. Is that correct?
google Api Explorer Check this site to see for which api you need which parameters.
I couldn't find a definitive answer for your question in the YouTube documentation for topicCategories, but I have some evidences that it is automatically calculated by YouTube.
First I couldn't find a way to set it in the configuration options of the channel I created.
Second, they used to have a (now deprecated) attribute called Guide Category they explicitly say:
A guideCategory resource identifies a category that YouTube algorithmically assigns based on a channel's content or other indicators, such as the channel's popularity. The list is similar to video categories, with the difference being that a video's uploader can assign a video category but only YouTube can assign a channel category.
So I believe that this Topic Category is automatically calculated by You Tube.

Pass an image get a list of URLs matching the image, HOW?

I'm essentially trying to do a reverse image search, i.e. I want to pass in an image and get back a results list of instances on the web where that image is found. I know Google's old API that did this is depreciated, I see some answers on SO (e.g. Google custom search for images only) that talk about doing an image search with Google's Custom Search API, but every time I dig into the code they are retrieving images from a string rather than what I'm trying to do. Is there currently any API that will help me with what I'm trying to do?
I'm sorry. I cannot write comments yet. How about this? https://github.com/tanaikech/goris
Recently, I found this. I don't know whether this is what you want.

Resources