Recently I looked at the community, the library has no relevant information about Python reptiles, based on the spirit of being a QUANT comprehensive development. Very, very superficial learning of reptile-related concepts and knowledge. After learning about "Reptile Technology" I found out that the pit is quite large, this article is just a first look at "Reptile Technology".
For new traders, it is always desirable to get the information about the exchange at the first time. It is obviously unrealistic to have people staring at the exchange's website all the time. So on demand, use reptile scripts to monitor the exchange's announcement page, detect new announcements and get notified at the first time.
A very simple program is used as an introduction (truly powerful crawler scripts are much more complicated, slowly come first). The program logic is very simple, it allows the program to continuously access the announcement page of the exchange, analyze the HTML content obtained, and detect whether the content of a specific tag is updated.
It is possible to use some useful reptile frameworks. However, it is also possible to write directly, considering the simplicity of the requirements.
The following libraries are required to use Python:requests
This is a library that is used to access web pages.bs4
It can be understood as a library for parsing HTML code on a web page.
The code is:
from bs4 import BeautifulSoup
import requests
urlBinanceAnnouncement = "https://www.binancezh.io/en/support/announcement/c-48?navId=48" # 币安公告页面地址
def openUrl(url):
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36'}
r = requests.get(url, headers=headers) # 使用requests库访问url,即币安的公告网页地址
if r.status_code == 200:
r.encoding = 'utf-8'
# Log("success! {}".format(url))
return r.text # 访问成功的话返回网页内容文本
else:
Log("failed {}".format(url))
def main():
preNews_href = ""
lastNews = ""
Log("watching...", urlBinanceAnnouncement, "#FF0000")
while True:
ret = openUrl(urlBinanceAnnouncement)
if ret:
soup = BeautifulSoup(ret, 'html.parser') # 把网页文本解析为对象
lastNews_href = soup.find('a', class_='css-1ej4hfo')["href"] # 查找特定的标签,获取href
lastNews = soup.find('a', class_='css-1ej4hfo').get_text() # 获取这个标签中的内容
if preNews_href == "":
preNews_href = lastNews_href
if preNews_href != lastNews_href: # 检测到标签发生变动,即有新的公告产生
Log("New Cryptocurrency Listing update!") # 打印提示信息
preNews_href = lastNews_href
LogStatus(_D(), "\n", "preNews_href:", preNews_href, "\n", "news:", lastNews)
Sleep(1000 * 10)
It can even be extended to detect new announcements; analyze new currencies in the announcement and automatically place new orders.
eth8888Traceback (most recent call last): File "
ShawnQiangAuthor Hi, I also wrote a crawler announcement for Bitcoin, and either the crawler with the API or the crawler on the homepage has a 30s delay, I don't know if you have solved this problem, can you talk to me, my vx Shawn Qiang 1125
dreamer1111I have a problem with your tactic, brother, because Binance announced that it can be crawled first, and I tested it and found that it was only delayed by more than 30 seconds.
slightly_drunkI've also captured the announcement of the token with selenium + chrome before, with the accompanying announcement screenshot.
Inventors quantify - small dreamsThe issue of the exchange, you can try again.
eth8888GetAccount: 503: {"code":"50001","data":[],"msg":"Service temporarily unavailable, please try again later. "} I changed my rental server. The original disk was replaced with this server, and this error was reported because of a server communication problem.
Inventors quantify - small dreamsOne-key deployment hosts, the server is limited in permissions and cannot be installed.
eth8888So I looked up the software that would be installed on my computer, and I was wondering how to install it on a host that I rented.
Inventors quantify - small dreamsYou can download the python installation library/packages from Baidu. There are many tutorials.
eth8888But how do you install it?
Inventors quantify - small dreamsThe host can install all the packages that are used in the python on the host's system.
Inventors quantify - small dreamsIn the policy, the consultation intervals are made, and the intervals are detected every 10 seconds.
Inventors quantify - small dreamsGood, thanks for supporting FMZ.
slightly_drunkI've been playing fmz for a while, I've seen a lot of your posts, I've shared a lot of dry goods, it's great, I've had more opportunities to communicate.
Inventors quantify - small dreamsI'm not going to say that I'm not a big fan of the 666, but I'm not a big fan of the 666.