Perl. Search for short domains-2 solutions

There are situations when you need to find a free and short domain, for example, three-character.
I chose the .net domain zone for myself

Method One:
On the internet it is possible to find not actual today bases, for example:
Https://www.domainresearchtool.com/lists/net.zone.gz
But the problem is that this base is for 2014 and it is already outdated. But in case you have a budget of about $30, you can buy this file up-to-date.
Scripts that will help to get all three-character domains from a file have been written in Perl.

open(my $fh, "<", "zone.txt") or die "Can't open file: $!";
open(my $wh, '>', "custom.txt") or die "Can't open file: $!";
$cou=0;
while (<$fh>) {
  my @array = split /\s+/, $_;
  if ((@array[1] eq "NS")&&(@array[0] ne $tmp)&&(length @array[0] == 3)){
    print $wh @array[0]."\n";
  }
  [email protected][0];
  $cou++;
  if ($cou%100000==0){
    print "$cou\n";
  }
}
close $fh;
close $wh;
open(my $fh, "<", "custom.txt")
or die "Can't open file: $!";
chomp(my @lines = <$fh>);
close $fh;
@list=sort @lines;
open(my $fh, ">", "sorted.txt")
or die "Can't open file: $!";
foreach (@list) {
  print $fh "$_\n";
}
close $fh;

 
This script takes all three-letter domains from the zone. txt file and saves them to the file custom. txt, and then sorts the found domains alphabetically and saves the sorted list to the file sorted. txt.

The second script:

open(my $fh, "<", "sorted.txt")
or die "Can't open file: $!";
chomp(@lines = <$fh>);
close $fh;
open(my $wh, '>', "free.txt") or die "Can't open file: $!";
my $cou=0;
@letters=('-','0'..'9','A'..'Z');
for(my $i=1; $i < scalar @letters; $i++){
  for(my $j=0; $j < scalar @letters; $j++){
    for(my $k=1; $k < scalar @letters; $k++){
      [email protected][$i][email protected][$j][email protected][$k];
      if(isPresent($dmn)<1){
        $cou++;
        print $wh $dmn."\n";
        if($cou %100 == 0){
          print $cou.", ";
        }
      }
    }
  }
}
close $wh;
print "ok";
sub isPresent(){
  my ($dmn)[email protected]_;
  foreach(@lines){
    if ($_ eq $dmn){
      return 1;
    }
  }
  return 0;
}

 
Loads the file sorted. txt and generates all possible combinations of three-character domains from 0-0 to ZZZ, then checks whether these domains exist in the sorted. txt file and if they are not, the file free. txt is created.
Just these names you will be able to use to select and register already your domain.

The second way:
If you do not have access to the actual files of domain zones, you can write a bot that will take all possible combinations of domain name, and using the command nslookup will find all unregistered. The problem is that if the domain is purchased but it is not recorded, it will be considered free-“Non-existent domain”, as a result, we get about 1000 false positives.

Listing bot:

print "Generating all domains names... \n";
my @domains;
@letters=('-','0'..'9','A'..'Z');
for(my $i=1; $i < scalar @letters; $i++){
  for(my $j=0; $j < scalar @letters; $j++){
    for(my $k=1; $k < scalar @letters; $k++){
      push @domains, @letters[$i][email protected][$j][email protected][$k].'.net';
    }
  } 
}
print "Scaning... \n"; unless(open FILE, '>free-domains.txt') {
  die "\nUnable to create $file\n";
}
close FILE;
my $cou=0;
foreach my $domain (@domains)
{
  chomp($domain);
  my $output = qx(nslookup -type=ns $domain 2>&1);
  my $r_c=$?;
  print "|";
  if((index $output, "Non-existent domain") > -1){
    print "\n".$domain."\n";
    open(my $wh, '>>', "free-domains.txt");
    print $wh $domain."\n";
    close($wh);
  }
  if($cou%1000==0){
  print "\nLast checked($cou): ".$domain."\n";
  }
  $cou++;
}

 
Bot saves everything as it considers free domains in the file free-domains. txt
The resulting list can be run through any bulk domain verification service, I used https://www.reg.ru/domain/new/bulk
Sending to check on 200-300 domains, through this service, you can quickly, iterate over the entire list, and free domains will fit in the Recycle Bin.
Here is the result of the search for today:

Selenium Webdriver + Java + XPath search item by URL part in href

When writing a bot for Instagram, using a stack of technologies selenium Webdriver, Java, XPath, encountered a problem.
Instagram is now trying to protect themselves from bots, so to disassemble it most interesting.
The task arose, to get the number of Posts, Followers, the Following on the user’s open profile.
This is what the HTML block code looks like, which contains this data in Instagram:

<ul class=" _3dEHb">
  <li class=" LH36I">
    <span class=" _81NM2">
      <span class="g47SY lOXF2">
        3
      </span> 
      posts
    </span>
  </li>
  <li class=" LH36I">
    <a class=" _81NM2" href="/username/followers/">
      <span class="g47SY lOXF2" title="153">
        153
      </span>
       followers
    </a>
  </li>
  <li class=" LH36I">
    <a class=" _81NM2" href="/username/following/">
      Following: 
      <span class="g47SY lOXF2">
        8
      </span>
    </a>
  </li>
</ul>

 
In total, we have three digits, which are represented in different ways, we use this code to get the data:

String posts=driver.findElement(By.xpath("//ul/li/span/span")).getText();
String followers=driver.findElement(By.xpath("//a[contains(@href,'followers')][1]//span")).getAttribute("title");
String following=driver.findElement(By.xpath("//a[contains(@href,'following')][1]//span")).getText();
System.out.println("Posts:     "+posts);
System.out.println("Followers: "+followers);
System.out.println("Following: "+following);

 
In order to get the number of posts:

<ul class=" _3dEHb">
  <li class=" LH36I">
    <span class=" _81NM2">
      <span class="g47SY lOXF2">
        3
.........

 
We use the XPath design://ul/li/span/span
We simply list the last nesting of the tree and as a result we get the contents-“3”

Next we will know the number of subscriptions:

.........
    <a class=" _81NM2" href="/username/followers/">
      <span class="g47SY lOXF2" title="153">
        153
      </span>
       followers
.........

 
//a[contains(@href,’followers’)][1]//span here we find the first encountered tag A, in href link of which, there is a substring followers, and take from it attributes of the span tag. The title attribute contains the number of subscribers. In the example, this number is 153.

Finally, we get the number of subscriptions:

.........
    <a class=" _81NM2" href="/username/following/">
      Подписки: 
      <span class="g47SY lOXF2">
        8
.........

 
//a[contains(@href,’following’)][1]//span  the same as in the second command, only the reference is searched for the occurrence of the following, and we are interested not the attribute, but the text, in this case 8.


The task was interesting, in the selection of the correct combination of XPath helped me online editors of XPath, none of them was not comfortable enough, so I can not recommend any one, but with them you can play with the XPath on a lot faster than Progonaya Options through the bot.