-1
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys


driver = webdriver.Chrome()
driver.get("""https://www.itemscout.io/keyword""")
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.input-keyword")))
c = WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="app"]/div/main/div/div/div/div[1]/div/div[1]/div[2]/label/div')))
c.click()

search = driver.find_element_by_class_name("""input-keyword""")
search.send_keys('레고')
search.send_keys(Keys.RETURN)
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CSS_SELECTOR, "table.body-table")))
html = driver.page_source
html = BeautifulSoup(html, 'html.parser')
tables = html.select('table')
table = pd.read_html(str(tables[1]))
print(table)

the result is [1 rows x 11 columns] and I want to print the row values of 4,6,7 columns. How can I do this ?

noah
  • 2,616
  • 13
  • 27
김우재
  • 19
  • 7
  • Please phrase your question as a [MRE](https://stackoverflow.com/help/minimal-reproducible-example). We shouldn't have to scrape data in order to answer your question unless there is an error specifically during the scraping process (which isn't the case here I don't think). In creating example data I'd recommend functionally equivalent English data as it will make it easier for a majority of users to understand the question and provide an answer. – noah Jan 28 '21 at 17:08
  • Hi! I'm a beginner in python and I want to explain in an easy way, but it's kind of hard for me to do that. Sorry ㅠ – 김우재 Jan 28 '21 at 17:16
  • 2
    So you have a dataframe and you want to get the values in a column by number. Use `df.iloc[:,[4,6,7]]`. – noah Jan 28 '21 at 17:20
  • Does this answer your question? [How to get column by number in Pandas?](https://stackoverflow.com/questions/17193850/how-to-get-column-by-number-in-pandas) – noah Jan 28 '21 at 17:22
  • Looking at your question do you see how all the code you provide is irrelevant? All we needed to know was you have a 1x11 df and that you wanted to access the elements in columns 4,6,7 – noah Jan 28 '21 at 17:24

1 Answers1

0

Try:

table[0].loc[:,[4,6,7]]

    4       6           7
0   476900  좋음 2.47 3791.0
Pygirl
  • 12,969
  • 5
  • 30
  • 43