Веб-сбор данных о запасах с помощью C#C#

Место общения программистов C#
Ответить
Гость
 Веб-сбор данных о запасах с помощью C#

Сообщение Гость »


I'm creating a .net web api with stock details that I've scraped from both Yahoo finance and Google finance but I need some help.
The first thing I noticed is that no one is using unique classes or IDs...
1.
Yahoo finance market price value (when live) is inside of a "span" which in turn is inside of a custom element "fin-streamer". The value it self is also in between ::before and ::after. I couldn't find a way to reach it so I had to take it from Google instead.
How would I reach a value which is in between ::before and ::after inside of a span?
2.
Scraping data from: https://finance.yahoo.com/quote/AAPL/financials
So here I tried scraping all the details from 2023 (09/29/2023) using divs with class="Ta(c) Py(6px) Bxz(bb) BdB Bdc($seperatorColor) Miw(120px) Miw(100px)--pnclg D(tbc)".
This kind of worked but for some reason I got all the values from 2023 AND from 2021 so I had to loop through and fix that in a list.
Also for some reason all of the values are inside spans EXCEPT "Basic EPS" and "Diluted EPS"...
**
I guess it all comes down to this: Is there an easier way of locating nodes when there is no unique class or unique ID? I'm currently using HtmlAgilityPack for the scraping.
My code at the moment would break instantly if Yahoo finance just made the smallest change to their "Financials" page, there must be a more robust way of coding this, right? **
For now everything works, you can open the API, search for a stock symbol and get:
  • Market price from Google
  • All Financials stats from Yahoo/financials for the last year (2023)
But the way I got here was clunky and felt off, I really hope there is an easier way of doing what I've done and in a more maintainable way.


Источник: https://stackoverflow.com/questions/781 ... th-c-sharp
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»