|
|
2
undetected Selenium
4 年前
从中提取内容
OMX斯德哥尔摩30
<table>
使用
Selenium
和
python
您可以使用以下内容
Locator Strategy
:
-
使用
XPATH
:
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//h4[text()='OMX Stockholm 30']//following::div[2]//table"))).text)
-
注:
:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
-
控制台输出:
VÃRDIPAPIR
KURS
ÃNDRING I %
ÃNDRING
VOLUME
BUD
UDBUD
OPDATERET
ABB LTD
229,60
0,13%
0,30
1.953.199 229,20 229,30 18.09.2020
ALFA LAVAL AB
210,50
1,20%
2,50
1.513.953 210,30 210,40 18.09.2020
ASSA ABLOY AB SER. B
216,00
1,55%
3,30
3.250.421 216,20 216,40 18.09.2020
ASTRAZENECA PLC
995,10
0,56%
5,50
507.005 994,70 995,00 18.09.2020
ATLAS COPCO AB SER. A
425,60
1,89%
7,90
2.313.361 425,80 426,10 18.09.2020
ATLAS COPCO AB SER. B
376,60
2,78%
10,20
971.096 376,60 376,90 18.09.2020
AUTOLIV INC. SDB
655,00
-1,18%
-7,80
279.485 656,80 657,40 18.09.2020
BOLIDEN AB
275,80
1,03%
2,80
2.450.311 276,60 276,80 18.09.2020
ELECTROLUX, AB SER. B
194,60
0,34%
0,65
1.381.656 195,00 195,10 18.09.2020
ERICSSON, TELEFONAB. L M SER.
98,26
1,30%
1,26
17.811.892 98,12 98,16 18.09.2020
ESSITY AB SER. B
306,40
-0,20%
-0,60
1.795.692 306,20 306,40 18.09.2020
GETINGE AB SER. B
188,10
1,65%
3,05
864.843 188,05 188,15 18.09.2020
HENNES & MAURITZ AB, H 
157,85
-1,68%
-2,70
5.188.908 157,85 157,90 18.09.2020
HEXAGON AB SER. B
677,20
0,06%
0,40
776.831 676,20 676,80 18.09.2020
INVESTOR AB SER. B
584,60
1,53%
8,80
1.681.508 585,00 585,20 18.09.2020
KINNEVIK AB SER. B
336,95
3,34%
10,90
1.118.689 336,35 336,55 18.09.2020
NORDEA BANK ABP
68,37
-1,85%
-1,29
11.846.193 68,45 68,48 18.09.2020
SANDVIK AB
185,10
1,54%
2,80
3.874.524 185,00 185,10 18.09.2020
SECURITAS AB SER. B
140,00
-0,53%
-0,75
1.545.060 140,20 140,35 18.09.2020
SKANDINAVISKA ENSKILDA BANKEN
81,38
-3,46%
-2,92
10.968.672 81,38 81,42 18.09.2020
更新
正如你在评论中提到的
…要么超时,要么我只能得到标题。。。
这实际上意味着我们的定位器是正确的,问题在于渲染,在这种情况下,你可以
scrollIntoView()
您可以使用以下解决方案:
driver.get('https://www.euroinvestor.dk/markeder/aktier/sverige/omx-stockholm-30/21')
driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//h4[text()='OMX Stockholm 30']"))))
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//h4[text()='OMX Stockholm 30']//following::div[2]//table"))).text)
|