Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The data is written in this format 2020-07-09 15:44:04, ['1.1351'] I need to get rid of the square brackets and single quotes. How to do it? I guess you need to dig towards regular expressions.

What I have tried:

Python
import requests
import pandas as pd
import datetime
from bs4 import BeautifulSoup
import time
import schedule
import re

def Tracerprice(stock_code):
    url = 'https://finance.yahoo.com/quote/EURUSD=X?p=EURUSD=X&.tsrc=fin-srch'
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'lxml')

    YahooPrice = soup.find_all('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text

    if YahooPrice == []:
        YahooPrice = '99999'

    return YahooPrice

HSI = ['']


for step in range(1, 100000):
    price = []
    col = []
    time_stamp = datetime.datetime.now()
    time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
    schedule.run_pending()
    time.sleep(0)
    for stock_code in HSI:
        price.append(Tracerprice('stock_code'))
    col = [time_stamp]
    col.append(price)
    df = pd.DataFrame(col)
    df = df.T
    df.to_csv('Yahoo_Real_Time.csv', mode='a', header=False)
    print(col)
Posted
Updated 8-Jul-20 20:26pm
v2

1 solution

Quote:
I guess you need to dig towards regular expressions.

I guess you need to dig towards regular expressions - it isn't my homework, and I can already use them.

If you want to get started with Regexes, then get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
When you have that see here: Regular Expression HOWTO — Python 3.8.4rc1 documentation[^] - its' a pretty trivial Regex you are looking at writing.
 
Share this answer
 
Comments
CPallini 9-Jul-20 2:27am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900