TypeError: descriptor 'readlines' of 'file' object needs an argument
TypeError: descriptor 'readlines' of 'file' object needs an argument
我每次 运行 都会收到这个错误,有人可以帮我吗
我想获取 url 并从我的 urls 列表中使用它,它在文本文件中
sewa.txt
那是代码
#encoding: utf-8
import random
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC
import time
usr = ('')
pwd = ('')
poo =unicode ("","utf-8")
driver = webdriver.Firefox()
# or you can use Chrome(executable_path="/usr/bin/chromedriver")
driver.get('https://m.facebook.com/groups/192674874113111/')
assert "Facebook" in driver.title
elem = driver.find_element_by_name("email")
elem.send_keys(usr)
elem = driver.find_element_by_name("pass")
elem.send_keys(pwd)
elem.send_keys(Keys.RETURN)
time.sleep(22)
File=open('/home/sharkawey/Desktop/sewa','r');
for line in file.readlines():
driver.get(line)
elem = driver.find_element_by_name("lgc_view_photo")
elem.send_keys(Keys.RETURN)
time.sleep(15)
driver.find_element_by_name("file1").send_keys("/media/sharkawey/THE HELL/2.jpg")
elem = driver.find_element_by_name("xc_message")
elem.send_keys(poo)
elem = driver.find_element_by_name("photo_upload")
elem.send_keys(Keys.RETURN)
那是错误
TypeError: descriptor 'readlines' of 'file' object needs an argument
你需要用到这个,
for line in File.readlines():
因为您声明的文件对象是 File
而不是 file
。 Python是一种区分大小写的语言,在引用变量时需要小心。
或
或者您可以使用 for line in File:
,因为文件对象本身就是一个迭代器。
我每次 运行 都会收到这个错误,有人可以帮我吗
我想获取 url 并从我的 urls 列表中使用它,它在文本文件中
sewa.txt
那是代码
#encoding: utf-8
import random
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC
import time
usr = ('')
pwd = ('')
poo =unicode ("","utf-8")
driver = webdriver.Firefox()
# or you can use Chrome(executable_path="/usr/bin/chromedriver")
driver.get('https://m.facebook.com/groups/192674874113111/')
assert "Facebook" in driver.title
elem = driver.find_element_by_name("email")
elem.send_keys(usr)
elem = driver.find_element_by_name("pass")
elem.send_keys(pwd)
elem.send_keys(Keys.RETURN)
time.sleep(22)
File=open('/home/sharkawey/Desktop/sewa','r');
for line in file.readlines():
driver.get(line)
elem = driver.find_element_by_name("lgc_view_photo")
elem.send_keys(Keys.RETURN)
time.sleep(15)
driver.find_element_by_name("file1").send_keys("/media/sharkawey/THE HELL/2.jpg")
elem = driver.find_element_by_name("xc_message")
elem.send_keys(poo)
elem = driver.find_element_by_name("photo_upload")
elem.send_keys(Keys.RETURN)
那是错误
TypeError: descriptor 'readlines' of 'file' object needs an argument
你需要用到这个,
for line in File.readlines():
因为您声明的文件对象是 File
而不是 file
。 Python是一种区分大小写的语言,在引用变量时需要小心。
或
或者您可以使用 for line in File:
,因为文件对象本身就是一个迭代器。