[英]how to run two activities at the same time in python
i want to make two lists from the same source of html data but i want to collect the data at the same time so as to avoid a possible change in the data.我想从 html 数据的同一来源制作两个列表,但我想同时收集数据以避免数据可能发生变化。
this is the code i have:这是我的代码:
lok = []
num = 6
for _ in range(num):
inner = driver.find_element_by_xpath(
"/html/body/div[1]/div[2]/div/div/div/div[2]/div/div/div/div[2]/div[2]/div/div/div[2]/div[5]/span[1]").get_attribute(
"innerHTML")
lok.append(inner)
time.sleep(3600)
print(lok)
lokk = []
nums = 7
for _ in range(nums):
inner = driver.find_element_by_xpath(
"/html/body/div[1]/div[2]/div/div/div/div[2]/div/div/div/div[2]/div[2]/div/div/div[2]/div[5]/span[1]").get_attribute(
"innerHTML")
lokk.append(inner)
time.sleep(3600)
print(lokk)
this code collects this data:此代码收集此数据:
lok = ['1', '2', '3', '4', '5', '6']
lokk = ['7', '8', '9', '10', '11', '12', '13']
my problem however is that by the time lokk
is being collected the time has changed and the values have changed as well.然而,我的问题是,当收集
lokk
时,时间已经改变,值也已经改变。 What i want to happen is this:我想要发生的是:
lok = ['1', '2', '3', '4', '5', '6']
lokk = ['1', '2', '3', '4', '5', '6', '7']
You can append to lokk
at the same time as lok
and then only collect one more value in the second loop您可以 append 与
lok
同时到lokk
然后在第二个循环中只收集一个值
lok = []
num = 6
for _ in range(num):
inner = driver.find_element_by_xpath(
"/html/body/div[1]/div[2]/div/div/div/div[2]/div/div/div/div[2]/div[2]/div/div/div[2]/div[5]/span[1]").get_attribute(
"innerHTML")
lok.append(inner)
lokk.append(inner) # also append to lokk
time.sleep(3600)
print(lok)
lokk = []
nums = 1 # only collect 1 more piece of data
for _ in range(nums):
inner = driver.find_element_by_xpath(
"/html/body/div[1]/div[2]/div/div/div/div[2]/div/div/div/div[2]/div[2]/div/div/div[2]/div[5]/span[1]").get_attribute(
"innerHTML")
lokk.append(inner)
time.sleep(3600)
print(lokk)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.