Introduction
This is a web scraping Code Golf challenge that attempts to take stock Name and price columns from the 'Most Active' list on this New York Times URL.
Why is this challenge interesting?
Challenge:
Scrape these figures from this NYT page and turn it into a data frame using the smallest number of bytes possible (IE: import pandas as pd
(should you choose to use Python) would give you a score of 19 (19 bytes). The data frame must be printed or returned as output.
Shortest Code by bytes wins the challenge. That's it!
Input:
import requests from bs4 import BeautifulSoup import pandas as pd url='https://markets.on.nytimes.com/research/markets/overview/overview.asp' def pull_active(url): # your code response = requests.get(url) if response.status_code == 200: print("Response Successful") else: print("Response Unsuccessful") return() bs_object = BeautifulSoup(response.content,'lxml') st_value = bs_object.find_all('td',class_='colPrimary') st_name = bs_object.find_all('a',class_="truncateMeTo1") x = [] y = [] for tag in st_name: x.append(tag.get_text()) for tag in st_value: y.append(tag.get_text()) data = {'Name': x[0:8], 'Price': y[0:8]} df = pd.DataFrame(data) return(df) pull_active(url)
Score: 773 bytes To beat it, any code under 773 bytes.
Output:
Name Price 0 General Electric Co 10.11 1 Advanced Micro Devices Inc 33.13 2 PG&E Corp 6.14 3 Fiat Chrysler Automobiles NV 14.98 4 Neuralstem Inc 1.83 5 AT&T Inc 38.20 6 GrubHub Inc 34.00 7 Twitter Inc 29.86
...
document.querySelector('tbody').innerText
\$\endgroup\$$('tbody')[0].innerText
\$\endgroup\$