Ping Baidu and google using Python scripts, pythonping

Source: Internet
Author: User

Ping Baidu and google using Python scripts, pythonping

Ping Service

Ping is an update Notification Service Based on the XML_RPC standard protocol. It is used for Blog to quickly notify the search engine of content updates, so that the search engine can capture and update content in a timely manner.

The computer is equivalent to the RPC Client, which is used to initiate a request to the RPC Server and accept the execution result of the method.

Python Implementation Method

Python has built-in XMLRPClib, which can easily process the XMLRPC protocol, saving the trouble of unpackaging packets.

The usage is very simple. The first import is:

import xmlrpclib

Generate an xmlrpc Server Object:

sever = xmlrpclib.ServerProxy(ServerProxy)

ServerProxy is the RPC server endpoint address of the search engine.

Then you can execute the RPC server method. Take Baidu as an example:

result = server.weblogUpdates.extendedPing(blog_name,index_addr,new_post_addr,rss_addr)

weblogUpdates.extendedPingIs the method to be executed. The four parameters in the brackets are required on the Baidu ping Service Page. Result is the execution result returned by the method.

Encapsulation code

Inping_allPut the link to be pinged in the function, and transmit the parameters as needed.

#!/usr/bin/env python# -*- coding:utf-8 -*-import jsonimport xmlrpclibfrom db import redisdef ping(ping_url, *args, **kwds): """args: site_name, site_host, post_url, rss_url.""" rpc_server = xmlrpclib.ServerProxy(ping_url) result = rpc_server.weblogUpdates.extendedPing(*args) print resultdef ping_all(*args, **kwds): ping_url_list = [ 'http://ping.baidu.com/ping/RPC2', 'http://rpc.pingomatic.com/', 'http://blogsearch.google.com/ping/RPC2', ] for url in ping_url_list: ping(url, *args, **kwds)def main(): client = redis.pubsub() client.subscribe(['ping']) while True: for item in client.listen():  if item['type'] == 'message':  msg = item['data']  if msg:   post = json.loads(msg)   print post   ping_all(post.get('site_name'), post.get('site_host'),    post.get('post_url'), post.get('rss_url'))def test(): site_name = "tech2ipo" site_host = "http://alpha.tech2ipo.com" post_url = 'http://alpha.tech2ipo.com/100855' rss_url = "http://alpha.tech2ipo.com/rss/alpha.tech2ipo.com" ping_all(site_name, site_host, post_url, rss_url)if __name__ == '__main__': main()

Summary

The above is all about this article. I hope this article will help you learn or use python. If you have any questions, please leave a message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.