Steelers Fan asks:
So, to my current understanding the function “scrape attribute” is used to get/find code that is “inside” of an attribute, but not to actually pull anything specific out of it?
And “find regular expression” is used to actually pull the desired text from some scraped code/text?
Using the element editor, it seems that the regular expression selector is used to target matches, but only under specific conditions? This is the part where I am getting lost. The same regex that works for me using “find regular expression”, will not work in the element editor. I am struggling to understand what I am doing wrong here…
I want to try and understand how to best use each of these scraping tools (particularly the proper use of the advanced element editor), but each new time I utilize regex, it gets more confusing than the last time…
It sounds like you mostly get it but I think if we look at a couple of examples it will help a lot.
The first part of your question asks:
“So, to my current understanding the function “scrape attribute” is used to get/find code that is “inside” of an attribute, but not to actually pull anything specific out of it?”
Which is correct.
But for anybody else watching who doesn’t quite get that let’s go over a quick example.
The scrape attribute function allows you to scrape the value of an attribute of an HTML element.
Once you have the value of the attribute you want you can further refine it with regex using the find regular expression function.
So scrape attribute scrapes the entire value of an attribute without any refinement. Then you can manipulate that data or refine it using a find regular expression.
Now onto the part about the advanced element editor, you ask about using regex in the element editor and just generally how to use it.
The advanced element editor is a tool that helps us tell Ubot what element we want to target.
When you use the element selector Ubot does its best job to try and find the unique element that you are clicking on.
But sometimes we need to refine or change that selection in some way. The advanced element editor makes this process a bit easier because we can see the source code of the element and we don’t have to manually type in the selector language because the advanced element editor will do that for us.
Now that we can see the HTML we can select an attribute to target by.
Using this we can tell Ubot exactly how to target the element. And we can use different match types as well. By default exact match is selected but there is also regular expression and wildcard.
Wildcard allows us to use a star as a wildcard character. This star represents anything and for any length until the end of the attribute.
Regular expression allows us to target attributes more specifically than a wildcard because we can use regex to specify what we expect to see. So for example you may only want to see numbers or letters.
But all of these match types are working to simply select the element attribute we are not changing the data we get from it. Ubot will scrape the entire attribute value and then after that you can change it if you want to.
So I hope that helps and if you like the video feel free to subscribe. I’ll be posting more videos on this channel soon.