I recently used python to improve efficiency and save time for my SEO work. I found that python is really good and can accomplish many things.
The following figure shows how to automatically update a website using python.ArticleThe replacement of the anchor text is also a good application for replacing multiple characters with a python string at a time.
The main idea is: there are some characters in an article that need to be used as the anchor text. My goal is to replace the characters with links and automatically add external links to the website, and for the diversity of links,
I used several candidate links to randomly set randomProgramChoose your own. If you know Seo, you should be clear about why.
Next I will mainly talk about the python program used. I hope you will have a good understanding of the need to replace multiple characters in another string.
I first defined a dictionary: The dictionary key mainly defines the keywords to be replaced, and the list below is
Linkcontent = {'keyword 1': ['link 1 (anchor text 1) ', 'link 2 (anchor text 2)'], 'keyword 2 ': ['link 1 (anchtext 1) ', 'link 2 (anchtext 2)'],
'Keyword 3': ['link 1 (anchor text 1) ', 'link 2 (anchor text 2)'], 'keyword 4 ': ['link 1 (anchtext 1) ', 'link 2 (anchtext 2 )','..... ', you need to add this keyword to replace the possibility of the anchor text
This ensures the diversity of external links.]
......
}
Definition Method
Def Multiple_replace (text, adict, num ):
'''Replace multiple times '''
RX = Re. Compile ( '|' . Join (MAP (Re. Escape, adict )))
Def One_xlat (MATCH ):
Rnum = Len (adict [match. Group ( 0 )])
Sortid = random. Choice (range (rnum )) # Random category
Return Adict [match. Group ( 0 )] [Sortid]
IfNum %2=0:
Textnum =3
Else:
Textnum =4
ReturnRx. sub (one_xlat, text, textnum)
Import re import random
Call: zcontent = multiple_replace (content, linkcontent, specified number of times)
Because I use a for each loop here, for I in range (300 ):
Zcontent = multiple_replace (content, linkcontent, I) in this way, we can generate three connections in half of the content in the article, and four in half.
If you only test the string replacement function, you can retain only the content and linkcontent parameters, and the specified number of times is unnecessary.
If you have any questions, please refer to the comments below. To implement this function, you can understand the multiple_replace function.