Pythonでは、「©」記号の前後に4人の傭船者を抽出しようとしていますが、このコードは©の後に文字を抽出します。あなたは、ほとんど存在し文字列の前後に文字を印刷しようとしています
if "©" in html:
pos_c = html.find("©")
symbol = html[pos_c-4:pos_c]
print symbol
Pythonでは、「©」記号の前後に4人の傭船者を抽出しようとしていますが、このコードは©の後に文字を抽出します。あなたは、ほとんど存在し文字列の前後に文字を印刷しようとしています
if "©" in html:
pos_c = html.find("©")
symbol = html[pos_c-4:pos_c]
print symbol
ここ©
import re
text = "This is all test and try things that's going on bro Copyright© Bro Code Bro"
print(re.findall(".{4}©.{4}", text))
出力の前と後の4つの文字を取得するために正規表現のみソリューションです:彼は私が抽出しようとしている `言っ
['ight© Bro']
を取得するために、文字列全体をしたくありません!
使用する検索あなたは
symbol=re.search(r"(?<=©).+$",html).start()
を好きなように、この場合には、上記の行は、あなたの試合の指標を与え、その後、インデックスとスライス/サイコロの文字列を取得するための63
使用
html[symbol:symbol+4] for post and html[symbol-4:symbol] for pre.
:印刷、ほんの数文字)このようにそれをやってみ
import re
html = "This is all test and try things that's going on bro Copyright© Bro Code Bro"
if "©" in html:
symbol=re.findall(r"(?<=©).+$",html,re.M)
print(symbol[0][0:100])
html = "This is all test and try things that's going on bro Copyright© Bro Code Bro"
html = html.split("©")
print(html[0][-4:])
print(html[1][:4])
出力:
ight
Bro
問題を解決するには、関数split()でビルドされたPythonを使用してください。
html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split('©')
あなたの解決策はこれを提供していません。 – moritzg
ありがとう、それは期待どおりに正確に働いた。 – Pandsh
@Pandsh喜んで助けることができました。 – moritzg