Ping Baidu and google using Python scripts

Source: Internet
Author: User
Recently, when I was doing SEO, in order to enable quick indexing of external links, I thought of using the ping function. both google and Baidu have related ping introduction, if you are interested, you can check related knowledge. The following article describes how to ping Baidu and google using a Python script. For more information, see. 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. extendedPing is the method to be executed. The four parameters in brackets are required on the Baidu ping Service page. Result is the execution result returned by the method.

Encapsulation code

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

#!/usr/bin/env python# -*- coding:utf-8 -*- import jsonimport xmlrpclibfrom db import redis  def 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 result  def 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.

For more articles about how to ping Baidu and google using Python scripts, refer to the PHP Chinese website!

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.