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