Importing External Data into Excel using Python
Вставка
- Опубліковано 3 гру 2024
- In this video I am going to show you how to import external data into your excel sheets. In this iteration, however, we are going to do this using web scraping with Python, BeautifulSoup and Requests. If this video was helpful please consider liking or subscribing - it would help me out a lot!
The Code for the Script:
import bs4
import requests
import openpyxl
wb = openpyxl.load_workbook('**File Path**')
sheet = wb['**Sheet Name**']
r = requests.get('finance.yahoo....)
soup = bs4.BeautifulSoup(r.text, features='html.parser')
priceAAPL = soup.find_all('div', {'class', 'D(ib) Mend(20px)'})[0].find('span').text.replace('.', ',')
v = sheet.cell(row=7, column=6).value = priceAAPL
wb.save('**File Path**')
Thx
I keep getting the variation in price instead of the value of the company. Any toughts? I've just repeated your code.
What software for python are you using
Hey Paul, you are probably referring to the IDE, which is the environment in which you code. I am using PyCharm