Python3 uses xpath to parse

1. When using xpath to parse the html page in the loop in Python3, the first value is repeated all the time, but print (tr.xpath ("string (.)")) The value of this code is looping all the time. It is suspected that the syntax of the following values is incorrect

.

the code is as follows:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from lxml import etree

chrome_options = Options ()
chrome_options.add_argument ("--headless")
chrome_options.add_argument ("--disable-gpu")
driver = webdriver.Chrome (executable_path = chromedriverwin32chromedriver.exeforth, Chrome_options=chrome_options)
url =" http://www.sse.com.cn/assortm."
driver.get(url)
time.sleep(5)
html = driver.page_source
selector = etree.HTML (html)
trEles = selector.xpath ("/ / * [@ id=" tableData_ "] / div [2] / table/tbody/tr")
for tr in trEles:

print(tr.xpath("string(.)"))
code = tr.xpath("//td/a/text()")[0]
companybbreviation = tr.xpath("//td[2]/text()")[0]
listingDate = tr.xpath("//td/text()")[3]

generalCapital = tr.xpath("//td/div/text()")[0]

LIQUI = tr.xpath("//td/div/text()")[1]

print(code + " : " + companybbreviation + " : " + listingDate+" : "+generalCapital+" : "+LIQUI)

print("-----------------------------------")![][1]

this is the printed value, all duplicated

Jul.22,2021

Hello, I ran this code and found that there was no error you mentioned.
printed normally:

AAAAA
600000 :  : 1999-11-10 : 2935208.04 : 2810376.39
-----------------------------------
6000006000001999-11-102935208.042810376.39
600000 :  : 1999-11-10 : 2935208.04 : 2810376.39
-----------------------------------

just runs a little slowly and hangs for a while after the following output:

DevTools listening on ws://127.0.0.1:56374/devtools/browser/929d1af7-8a8c-4bc7-bbb8-a19407b4ce9c

this should be due to slow page loading or slow network transmission, plus you have a sentence time.sleep (5) here, so you need to be patient to see the results.

Menu