I use Python 3.10.2 and selenium.
The flow is to enter the product code, scrap the displayed inventory, and save it to CSV, but as the number of products has increased, I would like to change it to loop processing.
The process I want to loop is as follows.
I'm thinking about increasing send_data(n) from 1 to 4000.
The send_data contains the product code in advance.
Thank you very much for letting me know.
driver.find_element_by_name("ban01").send_keys(send_data1)
driver.find_element_by_name("ban02").send_keys(send_data2)
driver.find_element_by_name("ban03").send_keys(send_data3)
driver.find_element_by_name("ban11").send_keys(send_data4)
driver.find_element_by_name("ban12").send_keys(send_data5)
driver.find_element_by_name("ban13").send_keys(send_data6)
driver.find_element_by_name("ban21").send_keys(send_data7)
driver.find_element_by_name("ban22").send_keys(send_data8)
driver.find_element_by_name("ban23").send_keys(send_data9)
driver.find_element_by_name("ban31").send_keys(send_data10)
driver.find_element_by_name("ban32").send_keys(send_data11)
driver.find_element_by_name("ban33").send_keys(send_data12)
driver.find_element_by_name("ban41").send_keys(send_data13)
driver.find_element_by_name("ban42").send_keys(send_data14)
driver.find_element_by_name("ban43").send_keys(send_data15)
driver.find_element_by_name("ban51").send_keys(send_data16)
driver.find_element_by_name("ban52").send_keys(send_data17)
driver.find_element_by_name("ban53").send_keys(send_data18)
driver.find_element_by_name("ban61").send_keys(send_data19)
driver.find_element_by_name("ban62").send_keys(send_data20)
driver.find_element_by_name("ban63").send_keys(send_data21)
driver.find_element_by_name("ban71").send_keys(send_data22)
driver.find_element_by_name("ban72").send_keys(send_data23)
driver.find_element_by_name("ban73").send_keys(send_data24)
driver.find_element_by_name("ban81").send_keys(send_data25)
driver.find_element_by_name("ban82").send_keys(send_data26)
driver.find_element_by_name("ban83").send_keys(send_data27)
driver.find_element_by_name("ban91").send_keys(send_data28)
driver.find_element_by_name("ban92").send_keys(send_data29)
driver.find_element_by_name("ban93").send_keys(send_data30)
time.sleep(3)
driver.find_element_by_xpath("xpath of send button").click()
time.sleep(3)
list0 = [driver.find_element_by_xpath("item name 0").text, driver.find_element_by_xpath(item name 0 in stock").text, send_data1, send_data2, send_data3]
list1 = [driver.find_element_by_xpath("item name 1").text, driver.find_element_by_xpath(item name 1 in stock").text, send_data4, send_data5, send_data6]
list2 = [driver.find_element_by_xpath("item name 2").text, driver.find_element_by_xpath(item name 2 in stock").text, send_data7, send_data8, send_data9]
list3 = [driver.find_element_by_xpath("item name 3").text, driver.find_element_by_xpath(item name 3 in stock").text, send_data10, send_data11, send_data12]
list4 = [driver.find_element_by_xpath("item name 4").text, driver.find_element_by_xpath(item name 4 in stock").text, send_data13, send_data14, send_data15]
list5 = [driver.find_element_by_xpath("item name 5").text, driver.find_element_by_xpath(item name 5 in stock").text, send_data16, send_data17, send_data18]
list6 = [driver.find_element_by_xpath("item name 6").text, driver.find_element_by_xpath(item name 6 in stock").text, send_data19, send_data20, send_data21]
list7 = [driver.find_element_by_xpath("item name 7").text, driver.find_element_by_xpath(item name 7 in stock").text, send_data22, send_data23, send_data24]
list8 = [driver.find_element_by_xpath("item name 8").text, driver.find_element_by_xpath(item name 8 in stock").text, send_data25, send_data26, send_data27]
list9 = [driver.find_element_by_xpath("item name 9").text, driver.find_element_by_xpath(item name 9 in stock").text, send_data28, send_data29, send_data30]
with open(r"CSV path\zaiko.csv", 'a', encoding="shift-jis", newline=') asf:
writer=csv.writer(f, lineterminator='\n')
writer.writerow (list 0)
writer.writerow (list1)
writer.writerow (list 2)
writer.writerow (list 3)
writer.writerow (list 4)
writer.writerow (list 5)
writer.writerow (list 6)
writer.writerow (list 7)
writer.writerow (list 8)
writer.writerow (list 9)
Only the send_data part has been extracted.When using it, please move the print() inside and use exec() etc.
max=10#Any maximum value
n = 0
while <max:
n + = 1
print("send_data" + str(n))
print("send_data"+str(3*n-2)+",send_data"+str(3*n-1)+",sand_data"+str(3*n))
For send_data in the above statement, see
+# string and numeric combinations
and
Convert to str()#str type (in this case, n from int type to str type)
This is achieved by attaching them together using , and in addition to the above, Send_data below is achieved by subtracting a certain number from the number that has tripled n.
Sorry for the confusing explanation.
572 Who developed the "avformat-59.dll" that comes with FFmpeg?
910 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
609 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.