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

Video Face Swap

Video Face Swap

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

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

How to run sublime code python How to run sublime code python Apr 16, 2025 am 08:48 AM

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

How to run python with notepad How to run python with notepad Apr 16, 2025 pm 07:33 PM

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

See all articles