Skip to content

Commit

Permalink
feat(yahoo): pass in user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
rodionlim committed Aug 30, 2024
1 parent 18693e7 commit ba6f12e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class StockScraperIntegrationTests
public async Task GetHTML_ValidTicker_ReturnsNonNullData()
{
// arrange
// var ticker = "ES3.SI";
var ticker = "O39.SI";
var ticker = "ES3.SI";

// act
var result = await Scraper.GetHTML(ticker);
Expand Down
6 changes: 4 additions & 2 deletions StockScraper/StockScraper/Scraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ExcelDna.Integration;
using ExcelDna.Registration;
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down Expand Up @@ -85,8 +86,9 @@ public static async Task<object> bdp(
internal static async Task<Dictionary<string, string>> GetHTML(string ticker)
{
var quoteSummary = new Dictionary<string, string>();
var config = Configuration.Default.WithDefaultLoader();
// new DefaultHttpRequester { Headers = { ["User-Agent"] = USER_AGENT } }
var htmlRequestor = new DefaultHttpRequester();
htmlRequestor.Headers["User-Agent"] = USER_AGENT;
var config = Configuration.Default.With(htmlRequestor).WithDefaultLoader();
var context = BrowsingContext.New(config);
var tickerUC = ticker.ToUpper();
var document = await context.OpenAsync($"https://sg.finance.yahoo.com/quote/{tickerUC}/");
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit ba6f12e

Please sign in to comment.