Unable to get Youtube Channel Name in node.js using Cheerio - node.js

I am not interested in using any API nor am I interested in any other library other than request-promie and cheerio. I am trying to get the name of a yt channel when I enter a link to the yt channel page. The text is inside a unique tag and is formatted like this: <yt-formatted-string id="text" class="style-scope ytd-channel-name">NAME OF CHANNEL</yt-formatted-string> I have tried the following
$('yt-formatted-string', html).text()
$('.ytd-channel-name', html).text()
$('div > yt-formatted-string', html).text()
and some other combinations but it seems as if the cheerio library is unable to recognize custom crafted tags such as "yt-formatted-string" as well as their attributes! Any suggestions on how to get past this?

Could you please try the below fragment? It works for me,
const $ = cheerio.load(`<yt-formatted-string id="text" class="style-scope ytd-channel-name">NAME OF CHANNEL</yt-formatted-string>`);
const a = $('yt-formatted-string').text(); //NAME OF CHANNEL

Related

Telegram Bot API: Send local/new photo into chat (Python 3.9)

I am struggling so hard on the following problem:
As the title says I want to send a picture via the Telegram Bot API. This is the code everyone is suggesting:
params = {'chat_id': chatId, 'caption':"This is a caption"}
img = {'photo': open(imgpath, 'rb')}
status = requests.post(sendPhotoURL, data=params, files=img)
Unfortunately, that does not work for me.
I've found out that in requests.post data should be params in order to create/post the URL correctly. But I haven't found a solution for sending the picture via the URL.
This is the code that is working for me (so far):
params = {'chat_id': chatId, 'caption':"This is a caption"}
img = {'photo': open(imgpath, 'rb')}
status = requests.post(sendPhotoURL, params=params, files=img)
print (status.url, "responsed:\n", status.status_code, ":", status.text)
I know the picture should be sent as a multipart/form-data (see: https://core.telegram.org/bots/api#sendphoto), which should be done by setting the parameter files to img (which is a dictionary). By doing it this way, i still get 400 : {"ok":false,"error_code":400,"description":"Bad Request: there is no photo in the request"}, so apparantly the API wants me to put the image into the URL.
It's very possible that I'm misunderstanding the docs or that I'm doing something incredible stupid. It would be so nice if any geeks could help me out :D!
Thanks a lot!
PS: I'm sorry for any typos or grammar/spelling mistakes. English is not my first language :D

Button has no ID and no Name, python Selenium

I want to make a little software with python and I have to get to YouTube with Requests-Python, but everytime I have to accept the Cookie-License. So I started with Selenium, but i cant find the button ID and the name or the value,...
The Source Code:
<button class="VfPpkd-LgbsSe VfPpkd-LgbsSe-OWXEXe-k8QpJ VfPpkd-LgbsSe-OWXEXe-dgl2Hf nCP5yc AjY5Oe DuMIQc IIdkle" jscontroller="soHxf" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue; touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc; touchcancel:JMtRjd; focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;" jsname="higCR" aria-label=""><div class="VfPpkd-Jh9lGc"></div><span jsname="V67aGc" class="VfPpkd-vQzf8d" aria-hidden="true"></span><div class="VfPpkd-RLmnJb"></div></button>
Selenium has many options additionally to id.
For example, try to use css locator
locator = driver.find_element_by_css_selector(".VfPpkd-LgbsSe.VfPpkd-LgbsSe-OWXEXe-k8QpJ.VfPpkd-LgbsSe-OWXEXe-dgl2Hf.nCP5yc.AjY5Oe.DuMIQc.IIdkle")
Remove classes that do not make this locator unique to make the locator shorter.

How to add images to Actions on google carousel?

I'm in the process on making a actions on google project and I am wanting to add a carousel to the action.
I understand the code end of things of how to add it to your action, but I'm a bit confused on how you get the links for your images. So for example, I seen in googles tutorial for carousel they have this following code snippet (to get it started):
const IMG_URL_AOG = 'https://developers.google.com/actions/images/badges' +
'/XPM_BADGING_GoogleAssistant_VER.png';
const IMG_URL_GOOGLE_ALLO = 'https://allo.google.com/images/allo-logo.png';
const IMG_URL_GOOGLE_HOME = 'https://lh3.googleusercontent.com' +
'/Nu3a6F80WfixUqf_ec_vgXy_c0-0r4VLJRXjVFF_X_CIilEu8B9fT35qyTEj_PEsKw';
const IMG_URL_GOOGLE_PIXEL = 'https://storage.googleapis.com/madebygoog/v1'
+
'/Pixel/Pixel_ColorPicker/Pixel_Device_Angled_Black-720w.png';
const IMG_URL_MEDIA = 'http://storage.googleapis.com/automotive-
media/album_art.jpg';
const MEDIA_SOURCE = 'http://storage.googleapis.com/automotive-
media/Jazz_In_Paris.mp3';
// Constants for selected item responses
And if you actually type these links in, you will get something like this back. The last two are other media types, but same idea.
Could someone explain how getting the images/ image links works for carousel's with actions on google? Do you have to make a html page for that image or am I just overthinking this and you can take an image link from online and it will work (given the right size of course). I might have missed something in the docs.
Thanks for the help or suggestions!
To maybe provide further context, I'm going off of this doc

My spanish text is not being decoded on my Ionic Hybrid App

I'm using code like {{user.city}} in one of my templates to pull data from my MySQL DB on my Ionic Hybrid App.
On my frontend, For a value like
Bogotá
I get
Bogot&aacute
I made sure to set my DB collation to utf8_unicode_ci.
I tried searching and it seems I need to decode the entities, but I haven't been able to do so.I tried using:
<div ng-bind-html={{user.city}}></div>
Please bare in mind I have several values like this, not only one.
I'm also using an Ionic App I got from a code market, and I'm not very ionic-savvy, so if you could provide detail I would be very grateful!
Thanks!
David
You must encode the locations in php.
Then in your controller:
$http.get("path").success(function(response) {
var res =response.results;
var locationtext =[];
for (key in res){
//in this case your locationsTEXT is the locations from the API
locationtext.push(JSON.parse(res[key].locationsTEXT));
}
$scope.city = locationtext;
}
In view:
<ion-list>
<ion-item ng-repeat="point in city track by $index">
<p>{{point}}</p>
</ion-item>
</ion-list>
Keep in mind that, above code is a general solution. You must adapt this code according to your variables and needs.
Hope this helps!

Youtube API search auto-complete

I'm using Youtube API, I'd like to have a search auto-complete feature, just like on YouTube, when you type into the search input box, it gives you search suggestions.
I've read the docs, but still missing, Is this possible using the API?
Ok I found this URL:
http://suggestqueries.google.com/complete/search?client=firefox&ds=yt&q=Query
It isn't part of Youtube API, but still works, returns a JSON response.
For json just add "client" parameter:
http://suggestqueries.google.com/complete/search?client=youtube&ds=yt&client=firefox&q=Query
Above all apis are old and give google search suggestion not youtube search suggestion
Use this:
https://clients1.google.com/complete/search?client=youtube&gs_ri=youtube&ds=yt&q=faded
Extract suggestions using following JS code:
// data is response of above api
const data = 'window.google.ac.h(["faded",[["faded",0,[433]],["faded alan walker lyrics",0,[433]],["faded remix",0,[433]],["faded 8d",0,[433]],["faded piano",0,[433]],["faded wheel free fire",0],["faded karaoke",0,[433]],["faded ringtone",0,[433]],["faded instrumental",0,[433]],["faded live",0,[433]],["faded piano tutorial",0,[433]],["faded whatsapp status",0,[433]],["faded dhol cover",0,[433]],["faded dance",0,[433]]],{"k":1,"q":"_sPyvXmmbfcsVtfP4sgjOdKQAvg"}])';
const searchSuggestions = [];
data.split('[').forEach((ele, index) => {
if (!ele.split('"')[1] || index === 1) return;
return searchSuggestions.push(ele.split('"')[1]);
});
console.log(searchSuggestions);
Check Out YouTube AutoComplete Keyword Scraper . Not really sure of the context the person asking the question wants YouTube auto complete solution for but I thought I would throw this out there.
Also you can use JSON:
url: "https://suggestqueries.google.com/complete/search?client=youtube&ds=yt&q=" + i,
dataType: "jsonp",
The official one:
https://suggestqueries-clients6.youtube.com/complete/search?client=youtube-reduced&hl=en&gs_ri=youtube-reduced&ds=yt&cp=3&gs_id=100&q=Nectar&xhr=t&xssi=t&gl=us
You can choose country too.
P.S. I searched for Nectar in country US

Resources