我正在尝试解析一个 HTML 文件,该文件已在 Automator 中转换为 TXT 文件。
我之前使用 Automator 从网站下载了 HTML 文件,现在我正在努力解析源代码。
最好,我只想获取表格的信息,并且需要对 1800 个不同的 HTML 文件重复此操作。
这是源代码的示例:
</head>
<body>
<div id="header">
<div class="wrapper">
<span class="access">
<div id="fb-root"></div>
<span class="access">
Gold Account: <a class="upgrade" title="Account Details" href="http://www.hedge-professionals.com/account-details.html" >Active </a> Logged in as Edward | <a href="javascript:void(0);" onclick='logout()' class="logout">Sign Out</a>
</span>
</span>
</div><!-- /wrapper -->
</div><!-- /header -->
<div id="masthead">
<div class="wrapper">
<a href="http://www.hedge-professionals.com" ><img src="http://www.hedge-professionals.com/images/hedgep_logo_white.png" alt="Hedge Professionals Database" width="333" height="46" class="logo" border="0" /></a>
<div id="navigation">
<ul>
<li ><a href='http://www.hedge-professionals.com/dashboard.html' >Dashboard</a></li> …Run Code Online (Sandbox Code Playgroud) 我有这个字符串,它喜欢使用 Java 模式来分隔。第一行后面还有一个回车符。分隔符是 |
MSH|^~\&|Unicare^HL7CISINV10.00.16^L||IBA||||ADT^A03|3203343722|P|2.3.1|||||
EVN|A03
Run Code Online (Sandbox Code Playgroud)
我使用了以下代码。
Pattern pattern = Pattern.compile("([^|]++)*");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println("Result: \"" + matcher.group() + "\"");
}
Run Code Online (Sandbox Code Playgroud)
这样做基本上会显示每个分隔符的空字符。我想忽略这些。任何修改正则表达式的机会,以便可以忽略字符。
提前致谢。
我有包含多个查询的文件。如何使用 DELIMITER 将它们分开?我像在 mysql 中一样尝试过,但没有复制:
DELIMITER %
CREATE SEQUENCE logins_seq
INCREMENT BY 1
START WITH 1
%
CREATE TABLE logins (
login_name VARCHAR(64) NOT NULL
)
%
Run Code Online (Sandbox Code Playgroud)
如果没有分隔符,它会抛出错误:
CREATE SEQUENCE logins_seq
INCREMENT BY 1
START WITH 1
CREATE TABLE logins (
login_name VARCHAR(64) NOT NULL
)
Run Code Online (Sandbox Code Playgroud) 我有一个清单,即
my_list = ['a', 'b', 'c', 'd','e','f']
Run Code Online (Sandbox Code Playgroud)
我想以竖线或逗号分隔的格式打印出来,但是因为我的一些列表对象可以有逗号或竖线,所以我想在打印时用双引号将每个对象括起来
即输出应该是
"a"|"b"|"c"|"d"|"e"|"f" rather than a|b|c|d|e|f
Run Code Online (Sandbox Code Playgroud)
我无法在我的 python 版本上使用格式
我想在字符串末尾的每两个字符之前添加空格。
$str = 9010201;
Run Code Online (Sandbox Code Playgroud)
结果应该是9 01 02 01。
我尝试了chunk_split()and str_split(),但它只能从字符串的开头起作用,但不能从最后一个开始起作用。
有没有办法用多个分隔符分割 vimscript 字符串?我知道例如这会将字符串分割为每个'/':
split('C:/test/blub\bla\bla\bla.txt', '/')。
但是有没有办法用多个分隔符分割字符串呢?
例如:split('C:/test/blub\bla\bla\bla.txt', ['/', '\'])
将字符串按每个'/'和拆分'\'。
有没有办法做到这一点?
我知道有很多关于 CSV 文件中的空格分隔符的问题。
我有一个似乎用空格分隔的 CSV 文件。导入 Python 时,我尝试了所有代码以将空格标识为分隔符。但是,我不断收到错误消息。例如:
test_filepath = 'test_data.csv'
with codecs.open(test_filepath, "r", "Shift-JIS", "ignore") as file: # import UTF8 based csv file
test_df = pd.read_table( file, delim_whitespace=True )
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误:
EmptyDataError: No columns to parse from file
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时:
test_filepath = 'test_data.csv'
with codecs.open(test_filepath, "r", "Shift-JIS", "ignore") as file: # import UTF8 based csv file
test_df = pd.read_table( file, delimiter=" " )
Run Code Online (Sandbox Code Playgroud)
它给出了同样的错误。
当我尝试这个时:
test_filepath = 'test_data.csv'
with codecs.open(test_filepath, "r", "Shift-JIS", "ignore") as file: # import UTF8 based csv file …Run Code Online (Sandbox Code Playgroud) 我有一个Python字符串:hello, my name is "Joe". 当我尝试使用该csv模块进行编写时,我得到了"hello, my name is ""Joe""". 我希望看到的是"hello, my name is "Joe""。
当存在双引号时,是否有办法让 CSV 编写器不添加双引号?
代码:
s = 'hello, my name is "Joe"'
with open(filename, 'w', newline='', encoding='utf-8') as f_out:
writer = csv.writer(f_out)
writer.writerow([s])
Run Code Online (Sandbox Code Playgroud) 我想使用像这样的分隔符将一个大文本文件拆分为多个文本文件[TEST],如下所示:
texttexttext
texttexttext
texttexttext
[TEST] title1
texttexttext1
texttexttext1
texttexttext1
[TEST] title2
texttexttext2
texttexttext2
texttexttext2
[TEST] title3
texttexttext3
texttexttext3
texttexttext3
Run Code Online (Sandbox Code Playgroud)
它应该分成多个文本文件:
title1.txt 包含:
texttexttext1
texttexttext1
texttexttext1
Run Code Online (Sandbox Code Playgroud)
title2.txt 包含:
texttexttext2
texttexttext2
texttexttext2
Run Code Online (Sandbox Code Playgroud)
title3.txt 包含:
texttexttext3
texttexttext3
texttexttext3
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?