search
HomeBackend DevelopmentPython TutorialShare an example tutorial on using Python to boost page views

This article mainly introduces the example code of Python to automatically brush blog views. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look.

Source of ideas

By chance today, I heard others talking about the current “volume brushing” behavior, so I Piqued my curiosity. Then I looked at the requests module and it happened to be useful to me, so I wrote a simple test case. Miraculously, I discovered that this trick actually works. So what are you waiting for? Start brushing.

Prelude

The idea is very simple, just an implementation of sending a request, that’s it. The code is as follows:


headers = {
  'referer':'www.php.cn',
  'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36'
}

def getHtml(url,headers):
  req = urllib2.Request(url,headers=headers)
  page = urllib2.urlopen(req)
  html = page.read()
  return html

We just need to manually add the target URL and a header. Naturally, I will use my own to test it.

I tried running the code and it can indeed increase the number of views.

Slow growth

Since such a plan is feasible, it means that the idea is correct. So we naturally think of writing a loop. Wouldn’t this be able to achieve a massive increase in browsing?
Yes, I did. The code is as follows:

i= 0
while i < 10:
  url = &#39;jb51.net/marksinoberg/article/details/51501377&#39;
  getHtml(url,headers)

At the beginning, you can clearly see the increase in the number of blogs, (^^) Hee hee...it has begun to show results. But the good times didn't last long. I found that the number of views increased by 10 times. Just haha.

Then it cannot be added. It is estimated that the server has imposed certain restrictions on my access, otherwise it should be feasible.

Find every way to deal with the pit

As the saying goes, "There are policies from above, and countermeasures from below." Naturally, I couldn't be constrained by this, so I guessed that it was against my IP. Recorded. Then some limits were added to my number of visits.

My solution:

  1. Proxy IP for access: However, considering that there is no server, the proxy IP cannot be accessed. .

  2. Change IP: Since this is the case, then I will find a way to change my IP for access. So how do you change your IP? (I regret it now that I think about it. I didn’t pay attention to the computer network class at that time and didn’t learn IP spoofing well. Otherwise, it wouldn’t be able to be used now). But all roads lead to Rome, and I have other ways. As follows:

C:\Users\Administrator>ipconfig /release

Windows IP Configuration

Cannot perform any operations on the local connection, it has Disconnect media.

Wireless LAN Adapter Wireless Network Connection:

Connection-specific DNS suffix. . . . . . . :
Link-local IPv6 address. . . . . . . : fe80: :1d9f:d97b:fd16:1f6f%
Default gateway. . . . . . . . . . . . . :

Ethernet Adapter Local Area Connection:

Media status . . . . . . . . . . . . . : Media is down
Connection specific DNS suffix . . . . . . . : OurEDA.cn

Ethernet AdapterVMware Network Adapter VMnet1:

Connection-specific DNS suffix. . . . . . . :
Link-local IPv6 address. . . . . . . : fe80::359d:e81d:741:f257%1
IPv4 address . . . . . . . . . . . . . . : 192.168.229.1
Subnet mask . . . . . . . . . . . . . : 255.255.255.0
Default gateway. . . . . . . . . . . . . . . :

Ethernet AdapterVMware Network Adapter VMnet8:

Connection-specific DNS suffix. . . . . . . . :
Link-local IPv6 address. . . . . . . . . : fe80::94b1:d10f:b68:101d%1
IPv4 address. . . . . . . . . . . . : 192.168.244.1
Subnet mask . . . . . . . . . . . . . : 255.255.255.0
Default gateway . . . . . . . . . . . . . . :

Ethernet AdapterVirtualBox Host-Only Network:

Connection-specific DNS suffix. . . . . . . :
Link-local IPv6 address. . . . . . . : fe80::a5eb:545c:7d89:9451%
IPv4 address. . . . . . . . . . . . . . : 192.168.56.1
Subnet mask . . . . . . . . . . . . : 255.255.255.0
Default gateway. . . . . . . . . . . . . . :

Tunnel Adapter isatap.{4F399971-B739-4B71-BD79-E48233EEC9BE}:

Media Status . . . . . . . . . . . . : Media Disconnected
Connection specific DNS suffix. . . . . . . :

Tunnel Adapter isatap.{1860C94E-1007-4418-9A26-7D8AA8F06E15}:

Media Status . . . . . . . . . . . . . . : Media disconnected
Connection specific DNS suffix . . . . . . . :

Tunnel Adapter isatap.OurEDA.cn:

Media status . . . . . . . . . . . . : Media disconnected
Connection specific DNS suffix . . . . . . . :

Tunnel adapter isatap. dlut.edu.cn:

Media status . . . . . . . . . . . . . : Media disconnected
Connection-specific DNS suffix. . . . . . . . :

隧道适配器 isatap.{6F7F27ED-942E-4EFB-ACF2-A4E8793B161D}:

   媒体状态  . . . . . . . . . . . . : 媒体已断开
   连接特定的 DNS 后缀 . . . . . . . :

C:\Users\Administrator>ipconfig /renew

Windows IP 配置

不能在 本地连接 上执行任何操作,它已断开媒体连接。

无线局域网适配器 无线网络连接:

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : fe80::1d9f:d97b:fd16:1f6f%12
   IPv4 地址 . . . . . . . . . . . . : 192.168.58.70
   子网掩码  . . . . . . . . . . . . : 255.255.252.0
   默认网关. . . . . . . . . . . . . : 192.168.56.1

以太网适配器 本地连接:

   媒体状态  . . . . . . . . . . . . : 媒体已断开
   连接特定的 DNS 后缀 . . . . . . . : OurEDA.cn

以太网适配器 VMware Network Adapter VMnet1:

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : fe80::359d:e81d:741:f257%14
   IPv4 地址 . . . . . . . . . . . . : 192.168.229.1
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . :

以太网适配器 VMware Network Adapter VMnet8:

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : fe80::94b1:d10f:b68:101d%15
   IPv4 地址 . . . . . . . . . . . . : 192.168.244.1
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . :

以太网适配器 VirtualBox Host-Only Network:

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : fe80::a5eb:545c:7d89:9451%16
   IPv4 地址 . . . . . . . . . . . . : 192.168.56.1
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . :

隧道适配器 isatap.{4F399971-B739-4B71-BD79-E48233EEC9BE}:

   媒体状态  . . . . . . . . . . . . : 媒体已断开
   连接特定的 DNS 后缀 . . . . . . . :

隧道适配器 isatap.{1860C94E-1007-4418-9A26-7D8AA8F06E15}:

   媒体状态  . . . . . . . . . . . . : 媒体已断开
   连接特定的 DNS 后缀 . . . . . . . :

隧道适配器 isatap.OurEDA.cn:

   媒体状态  . . . . . . . . . . . . : 媒体已断开
   连接特定的 DNS 后缀 . . . . . . . :

隧道适配器 isatap.dlut.edu.cn:

   媒体状态  . . . . . . . . . . . . : 媒体已断开
   连接特定的 DNS 后缀 . . . . . . . :

隧道适配器 isatap.{6F7F27ED-942E-4EFB-ACF2-A4E8793B161D}:

   媒体状态  . . . . . . . . . . . . : 媒体已断开
   连接特定的 DNS 后缀 . . . . . . . :

是的,想必大家都看到了。核心的两个命令就是


// 更改路由表的配置
ipconfig / release // 释放网络,
ipconfig /renew  // 重新分配IP

这样基本上对于改变自己的IP是有点效果的。尤其是对局域网用户而言。

所以,我只需要在Python代码中调用系统的cmd命令,就可以动态的改变自己的IP了。也就达成了我的需求了

难题

虽然IP的问题解决了,但是这样刷的话,还是太慢。因为路由表的更新时需要时间的。而这和代码运行的速度比起来,真的是太慢太慢了。而且每次只能刷出十个浏览量,额。确实是比较的尴尬啊。费了这么大的劲,才刷了十个浏览量。怎么解决这个问题呢?

我其实也没有真正的解决这个问题,但是我发现这个限制也是不特别的强,因为我中途吃了个饭,回来的时候就发现原来的IP又可以刷了。大概45分钟左右的间隔吧!这是个突破点。
源码

其实思路很简单,就是想方设法的针对问题解决问题。不管对方的系统多么的坚固,也不可能是天衣无缝,总会有一种解决的办法的。下面是代码。


# coding:utf-8

#  author = &#39;Mark sinoberg&#39;
#  date = &#39;2016/5/26&#39;
#  Desc = 测试测试 刷新自己的博客的浏览量

import urllib2,re
from bs4 import BeautifulSoup

def getHtml(url,headers):
  req = urllib2.Request(url,headers=headers)
  page = urllib2.urlopen(req)
  html = page.read()
  return html

def parse(data):
  content = BeautifulSoup(data,&#39;lxml&#39;)
  return content

def getReadNums(data,st):
  reg = re.compile(st)
  return re.findall(reg,data)

url = &#39;http://jb51.net/marksinoberg/article/details/51493318&#39;
headers = {
  &#39;referer&#39;:&#39;http://jb51.net/&#39;,
  &#39;User-Agent&#39;:&#39;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36&#39;
}
i = 0
while i<24:
  html = getHtml(url,headers)
  content = parse(html)
  result = content.find_all(&#39;span&#39;,class_=&#39;link_view&#39;)
  print result[0].get_text()
  i = i +1

代码运行结果:

D:\Software\Python2\python.exe E:/Code/Python/MyTestSet/ulib2/AddWatcher.py
94人阅读
95人阅读
96人阅读
97人阅读
98人阅读
99人阅读
100人阅读
101人阅读
102人阅读
103人阅读
104人阅读
105人阅读
106人阅读
107人阅读
108人阅读
109人阅读
110人阅读
111人阅读
112人阅读
113人阅读
114人阅读
115人阅读
115人阅读
115人阅读

Process finished with exit code 0

比较好的地方就是使用了BeautifulSoup抓取了特定位置的数据,这里是对浏览量的抓取。从上面的结果也可以看出,一个IP抓取的数据量是有限制的,一般来说是10~30个,这里貌似是22次访问。

展望

其实我是可以做到一次运行多次刷新的效果的,但是这样做不是特别的正派,所以我就说一下自己的思路吧。

  1. Make a judgment on the result (views result). When two consecutive results are consistent, start python and execute the cmd command to update your IP. But this is a time-consuming operation. You can put it in a thread

  2. and then crawl your own blog list interface to get all your blog posts. Of course, simulated login is obviously used here. Then brush up the volume of each blog. Although this does not really solve the problem, it will have a good effect if a little adds up.

  3. Make a thread that regularly refreshes the amount and refresh it every XX time. At the end of the day, one article can probably get hundreds of visits. (I haven’t tried it and I don’t know)

The above is the detailed content of Share an example tutorial on using Python to boost page views. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are the alternatives to concatenate two lists in Python?What are the alternatives to concatenate two lists in Python?May 09, 2025 am 12:16 AM

There are many methods to connect two lists in Python: 1. Use operators, which are simple but inefficient in large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use the = operator, which is both efficient and readable; 4. Use itertools.chain function, which is memory efficient but requires additional import; 5. Use list parsing, which is elegant but may be too complex. The selection method should be based on the code context and requirements.

Python: Efficient Ways to Merge Two ListsPython: Efficient Ways to Merge Two ListsMay 09, 2025 am 12:15 AM

There are many ways to merge Python lists: 1. Use operators, which are simple but not memory efficient for large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use itertools.chain, which is suitable for large data sets; 4. Use * operator, merge small to medium-sized lists in one line of code; 5. Use numpy.concatenate, which is suitable for large data sets and scenarios with high performance requirements; 6. Use append method, which is suitable for small lists but is inefficient. When selecting a method, you need to consider the list size and application scenarios.

Compiled vs Interpreted Languages: pros and consCompiled vs Interpreted Languages: pros and consMay 09, 2025 am 12:06 AM

Compiledlanguagesofferspeedandsecurity,whileinterpretedlanguagesprovideeaseofuseandportability.1)CompiledlanguageslikeC arefasterandsecurebuthavelongerdevelopmentcyclesandplatformdependency.2)InterpretedlanguageslikePythonareeasiertouseandmoreportab

Python: For and While Loops, the most complete guidePython: For and While Loops, the most complete guideMay 09, 2025 am 12:05 AM

In Python, a for loop is used to traverse iterable objects, and a while loop is used to perform operations repeatedly when the condition is satisfied. 1) For loop example: traverse the list and print the elements. 2) While loop example: guess the number game until you guess it right. Mastering cycle principles and optimization techniques can improve code efficiency and reliability.

Python concatenate lists into a stringPython concatenate lists into a stringMay 09, 2025 am 12:02 AM

To concatenate a list into a string, using the join() method in Python is the best choice. 1) Use the join() method to concatenate the list elements into a string, such as ''.join(my_list). 2) For a list containing numbers, convert map(str, numbers) into a string before concatenating. 3) You can use generator expressions for complex formatting, such as ','.join(f'({fruit})'forfruitinfruits). 4) When processing mixed data types, use map(str, mixed_list) to ensure that all elements can be converted into strings. 5) For large lists, use ''.join(large_li

Python's Hybrid Approach: Compilation and Interpretation CombinedPython's Hybrid Approach: Compilation and Interpretation CombinedMay 08, 2025 am 12:16 AM

Pythonusesahybridapproach,combiningcompilationtobytecodeandinterpretation.1)Codeiscompiledtoplatform-independentbytecode.2)BytecodeisinterpretedbythePythonVirtualMachine,enhancingefficiencyandportability.

Learn the Differences Between Python's 'for' and 'while' LoopsLearn the Differences Between Python's 'for' and 'while' LoopsMay 08, 2025 am 12:11 AM

ThekeydifferencesbetweenPython's"for"and"while"loopsare:1)"For"loopsareidealforiteratingoversequencesorknowniterations,while2)"while"loopsarebetterforcontinuinguntilaconditionismetwithoutpredefinediterations.Un

Python concatenate lists with duplicatesPython concatenate lists with duplicatesMay 08, 2025 am 12:09 AM

In Python, you can connect lists and manage duplicate elements through a variety of methods: 1) Use operators or extend() to retain all duplicate elements; 2) Convert to sets and then return to lists to remove all duplicate elements, but the original order will be lost; 3) Use loops or list comprehensions to combine sets to remove duplicate elements and maintain the original order.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software