0
刮我想從下面這個網址bloomberg代碼廢數據。網絡使用python和BS4
我想獲取下列標籤及其相應的值的文本:
*
1. open.
2. previous close.
3. ytd return.
4. market_cap.
5. day range.
6. 52wk_range.
7. current_per_ratio.
8. shares_outstanding.
9. volume.
10. one_year_return.
11. Earnings_per_share.
12. price_sales.
13. divident_indecated_gross_yeild.
*
我嘗試過,但失敗了,不知道在Python中用bs4做正確的方法。
請指引我實現它,我想要的方式。
<div class="data-table data-table_detailed"><!-- no spaces --><div class="cell cell__mobile-basic cell__visible__even"> <div class="cell__label"> Open </div> <div
> class="cell__value cell__value_"> 1,040.40 </div> </div><!-- no spaces
> --><!-- no spaces --><div class="cell cell__mobile-basic"> <div class="cell__label"> Day Range </div> <div class="cell__value
> cell__value_"> 1,026.00 - 1,044.00 </div> </div><!-- no spaces --><!--
> no spaces --><div class="cell cell__mobile-basic cell__visible__even">
> <div class="cell__label"> Volume </div> <div class="cell__value
> cell__value_"> 2,580,677 </div> </div><!-- no spaces --><!-- no spaces
> --><div class="cell cell__mobile-basic"> <div class="cell__label"> Previous Close </div> <div class="cell__value cell__value_"> 1,040.45
> </div> </div><!-- no spaces --><!-- no spaces --><div class="cell
> cell__mobile-basic cell__visible__even"> <div class="cell__label">
> 52Wk Range </div> <div class="cell__value cell__value_"> 900.30 -
> 1,279.30 </div> </div><!-- no spaces --><!-- no spaces --><div
> class="cell cell__mobile-basic"> <div class="cell__label"> 1 Yr Return
> </div> <div class="cell__value cell__value_down"> -12.66% </div>
> </div><!-- no spaces --><!-- no spaces --><div class="cell
> cell__mobile-basic cell__visible__even"> <div class="cell__label"> YTD
> Return </div> <div class="cell__value cell__value_up"> 2.06% </div>
> </div><!-- no spaces --><!-- no spaces --><div class="cell "> <div
> class="cell__label"> Current P/E Ratio (TTM) </div> <div
> class="cell__value cell__value_"> 16.43 </div> </div><!-- no spaces
> --><!-- no spaces --><div class="cell cell__visible__even"> <div class="cell__label"> Earnings per Share (INR) (TTM) </div> <div
> class="cell__value cell__value_"> 62.76 </div> </div><!-- no spaces
> --><!-- no spaces --><div class="cell "> <div class="cell__label"> Market Cap (t INR) </div> <div class="cell__value cell__value_">
> 2.369 </div> </div><!-- no spaces --><!-- no spaces --> <div class="cell cell__visible__even"> <div class="cell__label"> Shares
> Outstanding (b) </div> <div class="cell__value cell__value_"> 2.297
> </div> </div><!-- no spaces --><!-- no spaces --><div class="cell ">
> <div class="cell__label"> Price/Sales (TTM) </div> <div
> class="cell__value cell__value_"> 3.47 </div> </div><!-- no spaces
> --><!-- no spaces --> <div class="cell cell__visible__even"> <div class="cell__label"> Dividend Indicated Gross Yield </div> <div
> class="cell__value cell__value_"> 2.45% </div> </div><!-- no spaces
> --></div>
for cell in soup.find_all("div", class_='data-table data-table_detailed'):
name = ""
namecell = cell.find("div", class_="cell__label", text=True)
if namecell is not None:
name = namecell.get_text(strip=True)
price_chage = cell.find("div", class_="cell__value cell__value").get_text(strip=True)
data+=("%s: Price Change: %s," % (name, price_chage))
請分享你已經嘗試了什麼。 – eLRuLL
對不起,我忘記了,更新了它。 @eLRuLL –