The following is about using Python It will be absolutely URL Replace with relative URL The content of , It's supposed to be used for yard farmers .
#!/usr/bin/env python
#
#
# author : cold night
# email : [email protected]
#
import pymongo
import re
from StringIO import StringIO
conn = pymongo.Connection()
db = conn.test
def replace_url():
results = db['test'].find()
db_coll = db['test']
def replace(r):
content = r.get('content')
if not content: return
content = StringIO(content)
content.seek(0)
result = StringIO()
for line in content.readlines():
t = regex.sub(r'1="2"', line)
result.write(t)
result.seek(0)
content = result.read()
if content:
r['content'] = content
_id = r.get('_id')
db_coll.update({'_id':_id}, r)
results = [replace(i) for i in results]
if __name__=="__main__":replace_url()
use Python It will be absolutely URL Replace with relative URL More articles about the code of
- Replace the space in a string with “%20”(C、Python)
Replace the space in a string with “%20” C Language : /* ----------------------------------- Call through function , Send the address to manipulate the string 1. First calculate the length of the replaced string 2. from ...
- Python The implementation will numpy Medium nan and inf,nan Replace it with the corresponding mean value
nan:not a number inf:infinity; It's just infinite numpy Medium nan and inf All are float type t!=t return bool An array of types ( matrix ) np.count_nonzero( ...
- python take url Turn it into a QR code image
take url Data into two-dimensional code data , Then turn the QR code image into base64 Format return import qrcode import io def url_image(self,url): img = qrcode.mak ...
- python The thread process of
Threads and processes What is thread A thread is an entity of a process , yes CPU Basic unit of dispatch and dispatch , It's a smaller, independent, basic unit than a process , The thread itself basically does not have system resources , Have only a few essential resources in operation , But it can be the same thread as ...
- phpcms Commented on url The replacement problem
In the whole project ip Before , In the comments url yes 127.0.1.113 Change to localhost after , Updated all url And caching , however v9_comment In the table url Field not updated . Think about it. There's only one place in the background to replace data ...
- python Applet , Replace the string in the file
[[email protected] ~]# cat passwd root:x:::root:/root:/bin/bash bin:x:::bin:/bin:/sbin/nologin daemon:x: ...
- adopt python take xml File conversion to html file
# Conversion of data types def main(): maxwidth = 100 # Used to specify the length of a field print_start() count=0 while True: ...
- Will have a special class name img Replace the label with [img][/img] label --javascript Regular expression practice
In the project , Maybe sometimes you need to add a special attribute to something special , Or a special Class. as follows : <!-- The first way to write it --> <img src="abc.jpg" f ...
- CoreThink Development ( Ten ) Replace the official homepage with HTML5-3D Wheel planting
effect : Resources have been uploaded to my download . http://download.csdn.net/detail/u012995856/9587206 1. Copy the resource file to CoreThink In the project corethin ...
Random recommendation
- EBS Submit request appears REP-3000 error
stay AIX When using concurrent requests to submit reports on , The following error occurred :REP-3000: Internal error starting Oracle Toolkit. This is because Report Server need X-Wind ...
- EF LEFT JON Association lookup
var query = (from a in context.OQC_INSPECTION_SAMPLE.Where(expression).Where(a => context.OQC_INS ...
- c# Empty txt The value of the text file
FileStream fs1 = null; try { fs1 = new FileStream(@"C:\db.txt", FileMode.Truncate, FileAcc ...
- Cracking the code interview
Recommend a Book <Cracking the code interview> Now in the 5th edition, Cracking the Coding Interview gives ...
- MIT- Notes on Linear Algebra (7-11)
The first 07 speak solve Ax=0 : The main variable , Special solution The rank of a matrix Rank(A): The number of principal elements of a matrix . find “ The main variable ”pivotvariables, Main column , That is, the column in which the principal element is located , Other columns , It's called the free column .( Free column means that it can be free or arbitrary ...
- java Set of wrong questions
analysis :java in ,JavaDoc Annotate with /** start ( Write in the middle ) With */ ending analysis :A Object is an instance of a class , It's not a collection , The rest is right analysis : The syntax for creating an object is : Class name Object name =new Class name ();, So the correct answer is ...
- en-zh( social problem )social problems-2
Let the screen replace the parents to accompany the children ? Who : It's not right ! No sedentary screen time for babies, WHO says Babies and toddlers should not ...
- LeetCode 888 Fair Candy Swap Problem solving report
Subject requirements Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy tha ...
- Jenkins Distributed build
Jenkins Distributed build Sometimes , If there is an example , It's a bigger , Heavier projects , It needs to be compiled and generated on many computers on a regular basis . And running all of these built up central machines may not be the best choice . under these circumstances , People can configure other Jenkin ...
- Novice partner log access specification C# Realization
Because the business function of the industry needs , Need to connect log with rookie , Submit the user login information of our system to rookie , Rookie analysis by analyzing logs , Check for some security issues . According to the standards provided by rookies , Realized C# Access to , Let's share with you , Let friends in need go less ...