Home Backend Development Python Tutorial Share an example tutorial on using Python to boost page views

Share an example tutorial on using Python to boost page views

Jun 16, 2017 am 10:27 AM
python 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
Copy after login

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)
Copy after login

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
Copy after login

这样基本上对于改变自己的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
Copy after login

代码运行结果:

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
Copy after login

比较好的地方就是使用了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 of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Do mysql need to pay Do mysql need to pay Apr 08, 2025 pm 05:36 PM

MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.

How to use mysql after installation How to use mysql after installation Apr 08, 2025 am 11:48 AM

The article introduces the operation of MySQL database. First, you need to install a MySQL client, such as MySQLWorkbench or command line client. 1. Use the mysql-uroot-p command to connect to the server and log in with the root account password; 2. Use CREATEDATABASE to create a database, and USE select a database; 3. Use CREATETABLE to create a table, define fields and data types; 4. Use INSERTINTO to insert data, query data, update data by UPDATE, and delete data by DELETE. Only by mastering these steps, learning to deal with common problems and optimizing database performance can you use MySQL efficiently.

MySQL can't be installed after downloading MySQL can't be installed after downloading Apr 08, 2025 am 11:24 AM

The main reasons for MySQL installation failure are: 1. Permission issues, you need to run as an administrator or use the sudo command; 2. Dependencies are missing, and you need to install relevant development packages; 3. Port conflicts, you need to close the program that occupies port 3306 or modify the configuration file; 4. The installation package is corrupt, you need to download and verify the integrity; 5. The environment variable is incorrectly configured, and the environment variables must be correctly configured according to the operating system. Solve these problems and carefully check each step to successfully install MySQL.

MySQL download file is damaged and cannot be installed. Repair solution MySQL download file is damaged and cannot be installed. Repair solution Apr 08, 2025 am 11:21 AM

MySQL download file is corrupt, what should I do? Alas, if you download MySQL, you can encounter file corruption. It’s really not easy these days! This article will talk about how to solve this problem so that everyone can avoid detours. After reading it, you can not only repair the damaged MySQL installation package, but also have a deeper understanding of the download and installation process to avoid getting stuck in the future. Let’s first talk about why downloading files is damaged. There are many reasons for this. Network problems are the culprit. Interruption in the download process and instability in the network may lead to file corruption. There is also the problem with the download source itself. The server file itself is broken, and of course it is also broken when you download it. In addition, excessive "passionate" scanning of some antivirus software may also cause file corruption. Diagnostic problem: Determine if the file is really corrupt

How to optimize MySQL performance for high-load applications? How to optimize MySQL performance for high-load applications? Apr 08, 2025 pm 06:03 PM

MySQL database performance optimization guide In resource-intensive applications, MySQL database plays a crucial role and is responsible for managing massive transactions. However, as the scale of application expands, database performance bottlenecks often become a constraint. This article will explore a series of effective MySQL performance optimization strategies to ensure that your application remains efficient and responsive under high loads. We will combine actual cases to explain in-depth key technologies such as indexing, query optimization, database design and caching. 1. Database architecture design and optimized database architecture is the cornerstone of MySQL performance optimization. Here are some core principles: Selecting the right data type and selecting the smallest data type that meets the needs can not only save storage space, but also improve data processing speed.

How to optimize database performance after mysql installation How to optimize database performance after mysql installation Apr 08, 2025 am 11:36 AM

MySQL performance optimization needs to start from three aspects: installation configuration, indexing and query optimization, monitoring and tuning. 1. After installation, you need to adjust the my.cnf file according to the server configuration, such as the innodb_buffer_pool_size parameter, and close query_cache_size; 2. Create a suitable index to avoid excessive indexes, and optimize query statements, such as using the EXPLAIN command to analyze the execution plan; 3. Use MySQL's own monitoring tool (SHOWPROCESSLIST, SHOWSTATUS) to monitor the database health, and regularly back up and organize the database. Only by continuously optimizing these steps can the performance of MySQL database be improved.

Solutions to the service that cannot be started after MySQL installation Solutions to the service that cannot be started after MySQL installation Apr 08, 2025 am 11:18 AM

MySQL refused to start? Don’t panic, let’s check it out! Many friends found that the service could not be started after installing MySQL, and they were so anxious! Don’t worry, this article will take you to deal with it calmly and find out the mastermind behind it! After reading it, you can not only solve this problem, but also improve your understanding of MySQL services and your ideas for troubleshooting problems, and become a more powerful database administrator! The MySQL service failed to start, and there are many reasons, ranging from simple configuration errors to complex system problems. Let’s start with the most common aspects. Basic knowledge: A brief description of the service startup process MySQL service startup. Simply put, the operating system loads MySQL-related files and then starts the MySQL daemon. This involves configuration

Does mysql need the internet Does mysql need the internet Apr 08, 2025 pm 02:18 PM

MySQL can run without network connections for basic data storage and management. However, network connection is required for interaction with other systems, remote access, or using advanced features such as replication and clustering. Additionally, security measures (such as firewalls), performance optimization (choose the right network connection), and data backup are critical to connecting to the Internet.

See all articles