2 回答
TA贡献1842条经验 获得超12个赞
我实际上去了Facebook网站并提取了源代码并快速写了一些东西来让你登录网站
import pandas as pd
from selenium import webdriver
# Open Browser and go to facebook logging page
browser = webdriver.Chrome(r'C:\Users\Hamza\Desktop\Python\chromedriver')
browser.get('https://facebook.com')
# Import csv file
data = pd.read_excel (r'C:\Users\Hamza\Desktop\testcsv.xlsx')
i = 0
while i == 0:
a = 0
Username = df.username
Password = df.password
# Sends username
id_box = driver.find_element_by_class_id('email')
id_box.send_keys(Username[a])
# Sends password
Pass_box = driver.find_element_by_class_name('pass')
Pass_box.send_keys(Password[a])
# Click login
Send = driver.find_element_by_css_selector("u_0_3")
Send.click()
try:
test = driver.find_element_by_class_name('pass')
id_box.clear()
Pass_box.clear()
except:
print("logged in")
break
a = a + 1
但是,这是假设您的 csv 文件将文件保存在名为 username 和 password 的列中,因此您可能需要对其进行调整
TA贡献1799条经验 获得超6个赞
我认为最好的方法是在 dict() 中打开 CSV 文件。这是我的代码,它可以帮助你们。忽略细节这只是我正在处理的文件。
with open('C:\Users\Hamza\Desktop\testcsv.csv','rt')as f:
data = csv.DictReader(f)
for detail in data:
numberOfBedrooms=detail['numberOfBedrooms']
numberOfBathrooms=detail['numberOfBathrooms']
pricePerMonth=detail['pricePerMonth']
adress=detail['adress']
description=detail['description']
square_feet=detail['square_feet']
bedrooms = driver.find_element_by_xpath('//*[@id="jsc_c_12" or text()="Number
of bathrooms"]')
bedrooms.send_keys(numberOfBathrooms)
循环遍历您的数据并将您想要的数据存储在变量中,然后使用变量来发送。就像我在示例卧室中所做的那样。send_keys(numberOfBathrooms)
添加回答
举报