1
私はthis siteを持っています。記事のタイトルの下に表示される記号(EXAS、ESNT、ENZ、CENT、AEE)を抽出したいと思います。私は初心者ですから、むしろ反ピリモンのアプローチを試みました:ウェブサイトの2つの文字列の部分文字列の間の抽出
import requests
link="https://www.zacks.com/commentary/99386/new-strong-buy-stocks-for-december-29th"
fetch_data = requests.get(link)
content = str((fetch_data.content))
# I know that in the source code the symbols appear between "tickers" and "publish_date" therefore:
tickers= "tickers :"
pd = "publish_date :"
Z= ("%s(.*)%s" % (tickers,pd))
result = re.search(Z, content)
print (result)
# Just printing out the substring between tickers and pd
Output: <_sre.SRE_Match object; span=(95142, 95213), match="tickers : [\\'EXAS\\',\\'ESNT\\',\\'ENZ\\',\\'CEN>
シンボルだけをプリントアウトするにはどうしたらいいですか?また、最後のシンボル 'CEN'は 'セント'として印刷され、 'AEE'シンボルも表示されません。これは
Symbols: EXAS, ESNT, ENZ, CENT, AEE
あるいは、少なくとも理想的である:
"tickers : [\\'EXAS\\',\\'ESNT\\',\\'ENZ\\',\\'CENT\\',\\'AEE\\]