我正在尝试使用python请求多次填写表格。我正在使用的数据在csv中。我正在阅读csv并填写表格。但是我面临问题。它是仅第一行而不是所有行的填充形式。
这些是代码:
import requests
from bs4 import BeautifulSoup
import csv
import time
import tkinter
from tkinter import *
from tkinter import messagebox
import time
import datetime
from datetime import date
import json
username = "xxx"
password = "xxx"
url = "xxx"
parse_url = "xxx"
commerial_url = "xxx"
def Residential():
global url, parse_url
t1 = time.time()
with open('Residential.csv') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
builderid = row[0]
buildername = row[1]
buildingname = row[2]
address = row[3]
city = row[4]
locality = row[5]
building_id = row[6]
property_type = list(map(int, row[7].split(",")))
status = row[8]
cdate = row[9]
bhk = row[10]
rnumber = row[11]
rurl = row[12]
payload = {"action":url,
"name":"",
"username":username,
"password":password,
"submit2":""}
with requests.session() as s:
s.post(url, payload)
form_data = {"project[builderid]":builderid,
"buildingName":buildingname,
"project[address]":address,
"city_id":city,
"locality_id":locality,
"building_id":building_id,
"finalCityLocality":"",
"prop_types[]":property_type,
"1_type":1,
"2_type":1,
"3_type":1,
"4_type":1,
"6_type":1,
"7_type":1,
"90_type":1,
"22_type":1,
"project[flag]":status,
"readyToMoveDate":"",
"project[completion_dt]":cdate,
"launchDate":"",
"ex_id":"",
"ehome_visibility":"N",
"project[exid_type]":"",
"tagline":"",
"project[source]":"OTHER",
"project[source]":"rera",
"project[tco_visibility]":"N",
"project[carpet_area_visibility]":"N",
"project[pp_visibility]":"N",
"project[plan]":"",
"brochure_url":"",
"project[video_url1]":"",
"project[video_url2]":"",
"project[video_url3]":"",
"project[description]":"",
"project[proj_specifics]":"",
"project[data_reference]":rurl,
"usp[one]":"",
"usp[two]":"",
"usp[three]":"",
"logo_url":"",
"projArea":"",
"areaUnit":"ACRES",
"countTowers":"",
"countFloors":"",
"countUnits":"",
"percentOpen":"",
"payplan_url":"",
"project[meta_title]":"",
"project[meta_description]":"",
"show_bsp":"Y",
"price_type":"MIN_MAX",
"project[pmay_eligible]":"N",
"project[rera_status]":"",
"project[rera_af_date]":"",
"project[rera_regno]":"",
"project[rera_url]":"",
"project[rera_reg_startDate]":"",
"project[rera_reg_expDate]":"",
"project[rera_reg_extended]":"N",
"project[rera_inf_source]":"",
"project[rera_other_source]":"",
"project[sales_person_id]":"",
"auth_advt_add":"",
"cid":"",
"user":"",
"CMDSubmit":"SUBMIT"}
s.post(parse_url, data=form_data)
print(form_data)
r = s.post(parse_url, data=form_data)
print(r)
t2 = time.time()
total = t2-t1
messagebox.showinfo("Info",f"Total Time taken to create residential xid is {total}")
root = Tk()
root.title("XID Creator")
v = IntVar()
Radiobutton(root, text="Residential", variable=v, value=1,height=1,width=30, command=Residential).pack(anchor=W)
Radiobutton(root, text="Commercial", variable=v, value=2,height=1,width=30, command=Commercial).pack(anchor=W)
root.mainloop()
每当我单击住宅时,它一次只能填写一个表格行,我该如何读取所有行并填写表格?
答案 0 :(得分:1)
我全部解决了。我刚刚删除了return语句,一切都变得顺利了。.我已经更新了代码