SoFunction
Updated on 2025-03-03

Analysis of the implementation method of PHP and fiddler packet capture and capture WeChat index applet data

This article describes the implementation method of PHP and fiddler packet capture and grab WeChat index applet data. Share it for your reference, as follows:

I have studied the WeChat index in the past two days. To crawl, according to the general idea, it is to use fiddler to crawl the mobile phone packet, then analyze and obtain the address and then request it.

It’s right to think of you this way. If you do this decisively, it’s too yang too simple. You can take a look at the following steps for WeChat crawling:

1. Start logging into the mini program

2. Get the token needed for access

3. Then this token gets data

The first difficulty is the login step of the mini program. You have to log in to WeChat before you can access the mini program, because the mini program is run based on WeChat. Therefore, when you log in, you need to use the value of js_code generated internally by WeChat. This step alone is a huge pit that is unsightly.

Well, in the case of one billionth of probability, you get this value, and then you get the search_key value, and a UNIX timestamp.

After that, you can get the data you want to do your best? ? ? ? ? ?

Young people, you still have to be a steady focus. . . WeChat has a system with access restrictions. If a certain frequency is requested, it will prompt that the operation will be frequent. So after you worked hard, there was still no practical result.

There is a solution online, which is to use the Lua language to cooperate with the touch elves to write a script to operate WeChat, similar to automatically grabbing red envelopes. After that, use this script to automatically enter keywords for querying, and then use the packet capture tool to obtain these requested contents.

For those who are not very clear about using the packet capture tool to obtain the request content, please refer to:https:///article/

Let’s not talk about the success rate of this solution. Let’s talk about efficiency first. Could it be that if you do this, WeChat won’t limit your request? ? ?

There are also various costs of learning a language. . .

Therefore, I used PHP and fiddler packet capture tool to design a simple and easy-to-learn data capture solution. Let me tell you one by one:

The first thing is to configure fiddler to save the crawled data locally.

Reference link:https:///article/

This is used to obtain the access token, and the core PHP code is as follows:

function get_search_key($path)
{
  $file = fopen($path, "r");
  $user=array();
  $i=0;
  while(! feof($file))
  {
    $user[$i]= mb_convert_encoding ( fgets($file), 'UTF-8','Unicode');
    $i++;
  }
  fclose($file);
  $user=array_filter($user);
  foreach ($user as $item_u => $value_u) {
    if(strstr($value_u,"search_key=")){
      $temp[] = $value_u;
    }
  }
  $end_url = end($temp);
  $reg = "#openid=[a-zA-Z0-9]++_[a-zA-Z0-9]++&search_key=\d++_\d++#isU";
  preg_match_all($reg,$end_url,$time);
  return $time[0][0];
}

Enter the address of the saved file and get the return value. Take this return value to make a request and you can get the data you want.

However, this thing is also flawed. The first thing is to configure the mobile phone to connect to the computer. Regarding this, I will add it in the comments later. Next is to configure fiddler to save the package to local files. Also, the program needs to be accessed by the mobile phone before it can run successfully. More troublesome.

For more information about PHP related content, please check out the topic of this site:Summary of usage of php socket》、《Summary of usage of php strings》、《Summary of PHP mathematical operation skills》、《PHP object-oriented programming tutorial》、《Complete collection of PHP array (Array) operation techniques》、《PHP data structure and algorithm tutorial》、《Summary of PHP Programming Algorithm"and"Summary of PHP network programming skills

I hope this article will be helpful to everyone's PHP programming.