2

I am trying to get a table from a website using python. Here is the prompt I ran in the terminal:



url = 'https://www.zonebourse.com/bourse/derives/investissement-palmares/?type=volumes'

page = requests.get(url)
df_list = pd.read_html(page.text)
df = df_list[0]
df.head()

When I run this in my terminal, nothing happens. Any help would be great.

1
  • Which table you are trying to scrap? Commented Sep 17, 2020 at 10:49

1 Answer 1

2

I suppose you want to get the main table found on the page, which is not df = df_list[0]:

import requests
import pandas as pd
from bs4 import BeautifulSoup


url = 'https://www.zonebourse.com/bourse/derives/investissement-palmares/?type=volumes'

page = requests.get(url)
soup = BeautifulSoup(requests.get(url).content, 'html.parser')

df_list = pd.read_html(str(soup.select('#deriv_result_0')))
df = df_list[0]
df.columns = df.loc[0, :]
df = df.loc[1:, :]
print(df)

Prints:

0   Mnemo     Var. Volume €  Type Type de produit          Sous-jacent          Emetteur Prix d'exercice
1   51O8B   -4.73%   504250  CALL          Turbos               CAC 40       BNP Paribas            4640
2   44IUC    5.81%   257752   PUT          Turbos               CAC 40              Citi            5524
3   8Z20S   45.70%   191678   PUT          Turbos               CAC 40  Société Générale            5125
4   B6G9Z  -22.30%   177796  CALL          Turbos  WFD Unibail Rodamco  Société Générale           26.04
5   2K03Z  -10.14%   143812  CALL  Warrant simple               CAC 40  Société Générale            5100
6   59FPC   11.70%   122434   PUT          Turbos               CAC 40              Citi            5247
7   316AZ  -21.09%   118643  CALL          Turbos  WFD Unibail Rodamco  Société Générale           25.21
8   21O7B    7.82%   109214   PUT          Autres               CAC 40       BNP Paribas             NaN
9   892JB   17.58%    97810   PUT          Turbos               CAC 40       BNP Paribas            5321
10  4T51S   28.63%    95571   PUT          Turbos               CAC 40  Société Générale            5170
11  9802B    3.56%    90600   PUT          Turbos               CAC 40       BNP Paribas            6217
12  19D2B   -7.22%    82250  CALL          Autres               CAC 40       BNP Paribas             NaN
13  65NVC  -15.79%    78790  CALL          Turbos               CAC 40              Citi            4900
14  2V79S  -26.83%    73490  CALL  Warrant simple  WFD Unibail Rodamco  Société Générale              50
15  20O7B   -7.21%    73460  CALL          Autres               CAC 40       BNP Paribas             NaN
16  17A3S  -25.47%    70804  CALL          Turbos               CAC 40  Société Générale            4990
17  66A6B  -10.86%    70650  CALL  Warrant simple               CAC 40       BNP Paribas            5000
18  1244Z   11.38%    64880   PUT          Turbos               CAC 40  Société Générale            5389
19  81I0B   -5.57%    63613  CALL          Autres               CAC 40       BNP Paribas             NaN
20  034LB    0.00%    62090   PUT          Turbos               SAFRAN       BNP Paribas           111.4
21  55B4B   -6.25%    58450  CALL  Warrant simple          BNP Paribas       BNP Paribas              35
22  4N79S   14.39%    56055   PUT          Turbos               CAC 40  Société Générale            5200
23  8W48S   12.41%    54398  CALL          Turbos                Ipsen  Société Générale           80.46
24  SR15S    6.71%    54337   PUT          Autres               CAC 40  Société Générale             NaN
25  64M0B    4.42%    51712   PUT          Autres               CAC 40       BNP Paribas             NaN
26  12MJC   13.44%    51500   PUT          Turbos               CAC 40              Citi            5500
27  1U42S   -9.53%    50135  CALL          Turbos               CAC 40  Société Générale            4829
28  11DYC  -31.11%    50124  CALL          Turbos  WFD Unibail Rodamco              Citi           30.67
29  YS93V  -14.37%    49700  CALL          Turbos               CAC 40          Vontobel            4890
30  072PB    4.30%    49255   PUT          Autres               CAC 40       BNP Paribas             NaN
31  581OB   16.50%    48642   PUT  Warrant simple               CAC 40       BNP Paribas            5000
32  07C0S   29.41%    48470   PUT          Turbos               CAC 40  Société Générale            5097
33  63A6B  -12.10%    47800  CALL  Warrant simple               CAC 40       BNP Paribas            5000
34  17A0S  -20.91%    47675  CALL          Turbos               CAC 40  Société Générale            4960
35  93YAC   -9.09%    47370  CALL  Warrant simple                Total              Citi              32
36  EL69S   94.29%    46592   PUT          Turbos  WFD Unibail Rodamco  Société Générale           42.98
37  17R0Z   17.92%    46539   PUT          Turbos               CAC 40  Société Générale            5157
38  039OB   -2.18%    46020  CALL          Turbos               CAC 40       BNP Paribas            3871
39  126KZ    6.49%    45269   PUT          Turbos               CAC 40  Société Générale            5449
40  UL51V    4.36%    45190   PUT          Turbos               CAC 40          Vontobel            5316
Sign up to request clarification or add additional context in comments.

2 Comments

Just by curiosity, how did you know you had to select '#deriv_result_0' to before getting the desired table
@RasorVolt I opened Firefox Developer tools and looked how I could identify the table. There are many ways how to identify it, but this ID seems unique and contains the desired <table>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.