Sep-21-2023, 02:00 PM
(This post was last modified: Sep-21-2023, 02:58 PM by snippsat.
Edit Reason: Added code tag
)
Hi, I am trying to learn Scraping Data from Website with python and i tried extract that list ( List of largest companies by revenue - Wikipedia ) but it shows 60 columns instead of 8. I added the picture where i confused. ( ‘USD millions’ should be the last column but it continues like 1, 2, 3…). and i added the code. How should i fix it?
That's the code:
That's the code:
from bs4 import BeautifulSoup import requests url = 'https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue' page = requests.get(url) soup = BeautifulSoup(page.text, 'html') print(soup) soup.find_all('table') soup.find('table', class_ = 'wikitable sortable ') table = soup.find_all('table')[1] print(table) world_titles = table.find_all('th') world_titles world_table_titles = [title.text.strip() for title in world_titles] print ( world_table_titles) import pandas as pd df = pd.DataFrame(columns = world_table_titles) df column_data = table.find_all('tr') for row in column_data[2:]: #baştaki boşluk gitti row_data = row.find_all('td') individual_row_Data = [data.text.strip() for data in row_data] lenght = len(df) df.loc[lenght] == individual_row_Data df
![[Image: Whats-App-Image-2023-09-21-at-16-57-48.jpg]](https://i.ibb.co/XYYZ40y/Whats-App-Image-2023-09-21-at-16-57-48.jpg)