You should use selenium for this.
You will also have to install proper driver (chromedriver or gekodriver)
(I use firefox, so gekodriver)
The following code is almost correct, you can finish:
You will also have to install proper driver (chromedriver or gekodriver)
(I use firefox, so gekodriver)
The following code is almost correct, you can finish:
import selenium from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from bs4 import BeautifulSoup from pathlib import Path import os import PrettifyPage import time class FetchEaton: def __init__(self): os.chdir(os.path.abspath(os.path.dirname(__file__))) url = 'http://www.eatonpowersource.com/cross-reference/' self.pp = PrettifyPage.PrettifyPage() self.get_xref_data(url) def get_xref_data(self, url): browser = self.start_browser() browser.get(url) time.sleep(1) searchbox = browser.find_element(By.XPATH, '//*[@id="Criteria_CompetitorPartNumber"]') searchbox.clear() searchbox.send_keys('0330D0') btn = browser.find_element(By.XPATH, '/html/body/div[5]/section/div/section/div[1]/div[1]/span/aside/form/div[1]/div/span/button/i').click() time.sleep(2) table = browser.find_element(By.XPATH, '/html/body/div[5]/section/div/section/div[1]/div[2]/div[3]/div/div[1]/div/div/table') allRows = table.find_elements(By.TAG_NAME, 'tr'); for row in allRows: cells = row.find_elements(By.TAG_NAME, 'td'); for cell in cells: print(cell.text) self.stop_browser(browser) def start_browser(self): caps = webdriver.DesiredCapabilities().FIREFOX caps["marionette"] = True return webdriver.Firefox(capabilities=caps) def stop_browser(self, browser): browser.close() if __name__ == '__main__': FetchEaton()Output:
Output:Filtration
Hydac 0330D003BHHC
Filtration V0334B2H03
Filtration
Hydac 0330D003BNHC
Filtration V0332B2C03
Filtration
Hydac 0330D005BHHC
Filtration V0334B2H10
Filtration
Hydac 0330D005BNHC
Filtration V0332B2C05
Filtration
Hydac 0330D010BHHC
Filtration V0334B2H10
Filtration
Hydac 0330D010BNHC
Filtration V0332B2C10