Selenium, using find_element but end up with half the website

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

I finished the linked tutorial and tried to modify it to get somethings else from a different website. I am trying to get the margin table of HHI but the website is coded in a strange way that I am quite confused.

I find the child element of the parent that have the text with xpath://a[@name=”HHI”], its parent is and contains the text I wanted but there is a lot of tags named exactly so I can’t just use xpath://font[@size=”2″].

Attempt to use the full xpath would print out half of the website content.

the full xpath:

/html/body/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[3]/td/pre/font/table/tbody/tr/td[2]/pre/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font/font

Is there anyway to select that particular font tag and print the text?

website:
https://www.hkex.com.hk/eng/market/rm/rm_dcrm/riskdata/margin_hkcc/merte_hkcc.htm

Tutorial
https://www.youtube.com/watch?v=PXMJ6FS7llk&t=8740s&ab_channel=freeCodeCamp.org

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import pandas as pd
# prepare it to automate
from datetime import datetime
import os
import sys
import csv

application_path = os.path.dirname(sys.executable) # export the result to the same file as the executable

now = datetime.now() # for modify the export name with a date
month_day_year = now.strftime(“%m%d%Y”) # MMDDYYYY

website = “https://www.hkex.com.hk/eng/market/rm/rm_dcrm/riskdata/margin_hkcc/merte_hkcc.htm”
path = “C:/Users/User/PycharmProjects/Automate with Python – Full Course for Beginners/venv/Scripts/chromedriver.exe”

# headless-mode
options = Options()
options.headless = True

service = Service(executable_path=path)
driver = webdriver.Chrome(service=service, options=options)
driver.get(website)

containers = driver.find_element(by=”xpath”, value=”) # or find_element

hhi = containers.text # if using find_element, = containers[0].text

print(hhi)

‫أضف إجابة

تصفح
تصفح

مجهول يجيب