'blue'
次の形式のテキストを含むのクラスを持つすべてのスパンを見つけるにはどうすればよいですか:
04/18/13 7:29pm
したがって、次のようになります。
04/18/13 7:29pm
また:
Posted on 04/18/13 7:29pm
これを行うためのロジックを構築するという点では、これは私がこれまでに得たものです:
new_content = original_content.find_all('span', {'class' : 'blue'}) # using beautiful soup's find_all
pattern = re.compile('<span class=\"blue\">[data in the format 04/18/13 7:29pm]</span>') # using re
for _ in new_content:
result = re.findall(pattern, _)
print result
https://stackoverflow.com/a/7732827とhttps://stackoverflow.com/a/12229134を参照して、これを行う方法を見つけようとしましたが、これまでに得たのは上記だけです.
編集:
シナリオを明確にするために、次のスパンがあります。
<span class="blue">here is a lot of text that i don't need</span>
と
<span class="blue">this is the span i need because it contains 04/18/13 7:29pm</span>
04/18/13 7:29pm
残りのコンテンツは 必要ないことに注意してください。
編集2:
私も試しました:
pattern = re.compile('<span class="blue">.*?(\d\d/\d\d/\d\d \d\d?:\d\d\w\w)</span>')
for _ in new_content:
result = re.findall(pattern, _)
print result
エラーが発生しました:
'TypeError: expected string or buffer'