获取WP网站内文章中失效的图片

发布日期:
import mysql.connector
import re
import requests
connection = mysql.connector.connect(host='localhost',
                                     database='wordpress',
                                     user='root',
                                     password='')

sql_select_Query = "select post_content,ID,post_title from wp_posts where post_status='publish' and post_type='post'"
cursor = connection.cursor()
cursor.execute(sql_select_Query)
# get all records
records = cursor.fetchall()

p = re.compile(r'<img.+?src=[\'"]([^\'"]+)[\'"].*?>')
fw=open('urls.txt','w', encoding='utf-8')
images = []

for i in records:
    # print(i[0])
    urls = p.findall(i[0])
    if len(urls):
        for url in urls:
            if(requests.get(url).status_code!=200):
                print(url)
                fw.write(str(i[1]) + ' ' + i[2] + '\n')
                fw.write(url + '\n')