Python completes Baidu's Google Ping function

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. In addition to some open-source blogsProgramFor example, WP can set the ping address in the background. After setting the ping address, you can send a post to automatically notify the search engine that my blog has been updated, today, I am using a method that does not use WP or other blogs with the Ping function. I use python to ping the search engine locally to achieve quick indexing. AttachedCode:

Import re

Urlinfo ='''Http: // www.cnpythoner.com/post/181.html
Url2url3
'''

DefPing (webname, hosturl, linkurl ):
Import xmlrpclib
Rpc_server = xmlrpclib. serverproxy ('Http: // blogsearch.google.com/ping/rpc2')
Result = rpc_server.weblogupdates.extendedping (webname, hosturl, linkurl)

Print result
If result. get ( 'flerror' , false) = true:
Print 'Ping error'
else :
Print 'Ping SUCCESS '

DefGet_url (URL ):
'''Get standard url '''

Host_re = Re. Compile (R' ^ HTTPS? ://(.*?) ($ | /)',
Re. ignorecase
)

ReturnHost_re.search (URL). Group (0)

Info = urlinfo. Split ('\ N')

ForMInInfo:
Webname = M. Split ('.')[1]
Hosturl = get_url (m)
Ping (webname, hosturl, m)

If the returned result is {'message': 'Thanks for the ping. ', 'flerror': false}, the Ping is successful. Congratulations.

I hope to help you. It is mainly used in Python xmlrpclib.

Related Article

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.