Skip to content

How to use download news #31

Description

@gigascake

May be, proxing url broken?

start_date = "2024-09-01"
end_date = "2024-09-31"
config = {
"use_proxy": "us_free", # use proxies to prvent ip blocking
"max_retry": 5,
"proxy_pages": 5,
"token": "XXXXXX" # Available at https://finnhub.io/dashboard <-- inputed finnhub token api
}

news_downloader = Finnhub_Date_Range(config) # init
news_downloader.download_date_range_stock(start_date,end_date) # Download headers
news_downloader.gather_content() # Download contents
df = news_downloader.dataframe
selected_columns = ["headline", "content"]
df[selected_columns].head(10)


---> 10 news_downloader = Finnhub_Date_Range(config) # init
11 news_downloader.download_date_range_stock(start_date,end_date) # Download headers
12 news_downloader.gather_content() # Download contents

File ~/gitlab/FinNLP/finnlp/data_sources/news/finnhub_date_range.py:16, in Finnhub_Date_Range.init(self, args)
15 def init(self, args = {}):
---> 16 super().init(args)
17 assert "token" in args.keys(), "Please input your finnhub token. Avaliable at https://finnhub.io/dashboard"
18 self.finnhub_client = finnhub.Client(api_key=args["token"])

File ~/gitlab/FinNLP/finnlp/data_sources/news/_base.py:6, in News_Downloader.init(self, args)
5 def init(self, args = {}):
----> 6 super().init(args)
7 pass

File ~/gitlab/FinNLP/finnlp/data_sources/_base.py:22, in FinNLP_Downloader.init(self, args)
20 else:
21 self.proxy_id = 0
---> 22 self.proxy_list = self._update_proxy()
23 else:
24 self.proxy_list = []

File ~/gitlab/FinNLP/finnlp/data_sources/_base.py:44, in FinNLP_Downloader._update_proxy(self)
42 return get_china_free_proxy(self.proxy_pages)
43 else:
---> 44 return get_us_free_proxy(self.proxy_pages)

File ~/gitlab/FinNLP/finnlp/utils/get_proxy.py:86, in get_us_free_proxy(pages)
84 content = scripts[3].xpath(".//text()")
85 pattern = re.compile('LIST",data:(.+),added:')
---> 86 result_list = pattern.findall(content[0])
87 result_list = result_list[0].strip("[{").strip("}]").split("},{")
89 for result in result_list:

IndexError: list index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions