I want to get a string from different website and to display on mine.

The website have this HTML code inside it

<ul data-v-61cbae47="" class="b-tabs__nav m-tabs-default m-flex-width m-size-md m-mb-reset js-tabs-switchers m-over-separator">
   <li data-v-61cbae47="" class="b-tabs__nav__item m-current"><a data-v-61cbae47="" href="/jenawolfy" aria-current="page" class="b-tabs__nav__link m-with-rectangle-hover m-tb-sm router-link-exact-active router-link-active" id="profilePostTab"><span data-v-61cbae47="" class="b-tabs__nav__link__counter-title">130 posts</span></a></li>
   <li data-v-61cbae47="" class="b-tabs__nav__item"><a data-v-61cbae47="" href="/jenawolfy/media" class="b-tabs__nav__link m-with-rectangle-hover m-tb-sm"><span data-v-61cbae47="" class="b-tabs__nav__link__counter-title">132 Media</span></a></li>
   <!---->
</ul>

I want to get only these two strings 130 posts & 132 Media and to display on my website whenever is opened.

Is this possible to make in PHP or i need different language like python?

Assuming that:

  1. The structure is consistent and all posts and media counts will be displayed in that <span> tag, and
  2. You are reading the HTML line-by-line,

a regular expression could be useful.

<?php
$pattern = '/<span[^>]+>([\s\S]+)<\/span>/'; // @see https://stackoverflow.com/a/24029432

// Assuming that you fetch the HTML contents and add each read line to an array of lines
$lines = [
    '<ul data-v-61cbae47="" class="b-tabs__nav m-tabs-default m-flex-width m-size-md m-mb-reset js-tabs-switchers m-over-separator">',
    '<li data-v-61cbae47="" class="b-tabs__nav__item m-current"><a data-v-61cbae47="" href="/jenawolfy" aria-current="page" class="b-tabs__nav__link m-with-rectangle-hover m-tb-sm router-link-exact-active router-link-active" id="profilePostTab"><span data-v-61cbae47="" class="b-tabs__nav__link__counter-title">130 posts</span></a></li>',
    '<li data-v-61cbae47="" class="b-tabs__nav__item"><a data-v-61cbae47="" href="/jenawolfy/media" class="b-tabs__nav__link m-with-rectangle-hover m-tb-sm"><span data-v-61cbae47="" class="b-tabs__nav__link__counter-title">132 Media</span></a></li>',
    '<!---->',
    '</ul>',
];

// Get the text between <span> tags
foreach ($lines as $index => $line) {
    $index++; // Let's make it pretty & friendly
    preg_match($pattern, $line, $line_matches['Line ' . $index]);
}

// Let's make sure we matched all the <span> tags
var_dump($line_matches);

// Display only the text inside matched <span> tags
foreach ($line_matches as $line_match) {
    if (!empty($line_match[1])) {
        var_dump($line_match[1]);
    }
}
?>

Will result in:

/test.php:20:
array (size=5)
  'Line 1' => 
    array (size=0)
      empty
  'Line 2' => 
    array (size=2)
      0 => string '<span data-v-61cbae47="" class="b-tabs__nav__link__counter-title">130 posts</span>' (length=82)
      1 => string '130 posts' (length=9)
  'Line 3' => 
    array (size=2)
      0 => string '<span data-v-61cbae47="" class="b-tabs__nav__link__counter-title">132 Media</span>' (length=82)
      1 => string '132 Media' (length=9)
  'Line 4' => 
    array (size=0)
      empty
  'Line 5' => 
    array (size=0)
      empty

/test.php:25:string '130 posts' (length=9)

/test.php:25:string '132 Media' (length=9)

I believe this will help you get started. You may need to tweak the regex pattern in case the entire HTML has other <span> tags (for example, to look only for <span> tags with the class="b-tabs__nav__link__counter-title"> attribute), but for that you'll have to read up more on regular expressions.

Edit to clarify: I am sure there are other, more efficient, ways of doing this, and hopefully other contributors may want to share their approaches in PHP or other languages. This is just my immediate approach in PHP to your problem to hopefully point you in the right direction.

I found even smaller HTML code inside the website i want to scrape

<span data-v-7102f77e="" class="b-profile__sections__count"> 57 </span>

Only this will be enough info to scrape about the user
The website is onlyfans.com/[username] and the above html code is loading on every profile visited, but its not unique.

I see there are few more <span> tags with the same class and data-v-7102f77e=""

How do i request a crawl on that link (to get the data) when user from my website opens the same girl/model? I have the models [username] stored in Database.

How do i request a crawl on that link (to get the data) when user from my website opens the same girl/model? I have the models [username] stored in Database.

That, my friend, I don't know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.