【发布时间】:2019-01-22 16:18:03
【问题描述】:
我有一个数据库,我不知道你是否称它为数据库,但它已经到了那里,我们有多个来自旧公司文件的 URL,这些文件很混乱。我想用公司的新横幅/HTML 信息查找并替换多个 URL 的 .txt 文件。该脚本将与其他用 Python 编写的数据框程序(CVS 解析器)结合使用。这是我的代码。为什么我的 .TXT 文件没有被替换?
我尝试查看我知道是字符串的读取对象的输出。以及研究函数 replace() 的功能。
import json
import csv
class HTML_Parser:
def _init_(self, data):
data.self = data
F = open(r"C:\Users\Ultrarev\Desktop\Emeran-Parser\HTMLtoBeReplaced.txt",
"r")
str1 = F.read()
str1.replace("http://www.ultrarev.com/processedimages/ebay_layout/banner750x150 .jpg","https://xcart.amcoautoparts.com/ebay_layout/ebay_tmp_top.jpg")
str1.replace("http://www.ultrarev.com/processedimages/manufacturers/Ultrarev-
Footer.jpg","https://xcart.amcoautoparts.com/manufacturers/Ultrarev-F
ooter.jpg")
str1.replace("ULTRAREV INC.","AMCO Auto Parts, LLC")
str1.replace("ULTRAREV INC",'AMCO Auto Parts, LLC')
str1.replace("Should you have any question please call 1(877) 858-
7272.","Should you have any question, please message us!")
str1.replace("120 Central Ave. Farmingdale NJ 07727"," ")
str1.replace("CALL FOR CUSTOMER SUPPORT"," ")
str1.replace("Please Call us toll free 1-877-858-7272!","Should you have any
question, please message us!")
str1.replace('<a style="color: #000000; font-weight:bold; text-
decoration:none" href="tel:732-938-3999">'," ")
str1.replace('<a style="color: #000000; font-weight: bold; text-decoration:
none" href="tel:1-877-858-7272">1-877-858-7272</a>',' ')
str1.replace('<a style="color: #000000; font-weight: bold; text-decoration:
none" href="tel:732-938-3999">732-938-3999</a>',' ')
str1.replace(' OR ',' ')
str1.replace('OEM (Match Case) - Find them in both Title and Description',
'OE')
str1.replace("http://www.ultrarev.com", "https://xcart.amcoautoparts.com")
str1.replace('http://www.ultrarev.com/processedimages/manufacturers/ralco-
rz-
logo_texture.png', 'http://amcoautoparts.com/images/P/RalcoRZLogo.png')
print(str1)
我希望它返回一个带有替换值的字符串,而不是返回先前字符串的值。
【问题讨论】:
标签: python html python-3.x replace export-to-csv