_io.TextIOWrapper' 对象不可调用
_io.TextIOWrapper' object is not callable
我正在尝试打印以写入文件,其中包含什么类型的运输和物品
from bs4 import BeautifulSoup
from selenium import webdriver
stock_file = r"C:\Users\Tut10\Desktop\PSTool-Python\Final\test.txt"
def Home_Depot_Shipping(url):
driver = webdriver.Chrome(r"C:\Users\Tut10\Desktop\PSTool-Python\chromedriver.exe")
driver.get(url)
# open a file to write to
file_to_write = open(stock_file, "a")
# send that file to me via email or text
free_delivery = driver.find_elements_by_xpath(r'//*[@id="buybelt"]/div[2]/div[2]/div/div[2]')
for x in free_delivery:
#This should print one of the following options
# Free Delivery, Standard Delivery, or Receive an email blah blah blah
try:
if "Free Delivery" in x.text:
driver.quit()
file_to_write.close()
return "\t\t[+] Free Delivery"
elif "Get it as soon as tomorrow" in x.text:
driver.quit()
#file_to_write.write("Cell: " + str(cell) + "[*] Express Delivery " + url + '\n')
file_to_write.write("[*] Express Delivery " + url + "\n")
file_to_write.close()
return "\t\t[*] Express Delivery"
elif "Receive an email" in x.text:
driver.quit()
file_to_write("[-] Out of Stock %s\n" % url)
file_to_write.close()
return "\t\t[-] Out of stock!"
elif "Standard Delivery" in x.text:
driver.quit()
file_to_write.close()
return "\t\t[+] Standard Delivery"
except Exception as e:
driver.quit()
print(e)
Home_Depot_Shipping(r"https://www.homedepot.com/p/WEN-8-in-5-Speed-Drill-Press-4208/204853910?keyword=wen+4208")
我希望程序写入文件,如果交货是快递(明天尽快收到)或缺货(收到电子邮件)
只是随机的,我知道 def Home_Depot_Shipping 中的代码应该缩进。它只是不在这里复制。请忽略那个。它适用于免费送货和标准。当它尝试写入文件时,尽管我不断收到此错误
'_io.TextIOWrapper' object is not callable
如有任何建议或帮助,我们将不胜感激!
谢谢
也许你的意思是
file_to_write.write("[-] Out of Stock %s\n" % url)
而不是
file_to_write("[-] Out of Stock %s\n" % url)
作为一般规则,如果您注意,错误消息会得到足够好的提示
我正在尝试打印以写入文件,其中包含什么类型的运输和物品
from bs4 import BeautifulSoup
from selenium import webdriver
stock_file = r"C:\Users\Tut10\Desktop\PSTool-Python\Final\test.txt"
def Home_Depot_Shipping(url):
driver = webdriver.Chrome(r"C:\Users\Tut10\Desktop\PSTool-Python\chromedriver.exe")
driver.get(url)
# open a file to write to
file_to_write = open(stock_file, "a")
# send that file to me via email or text
free_delivery = driver.find_elements_by_xpath(r'//*[@id="buybelt"]/div[2]/div[2]/div/div[2]')
for x in free_delivery:
#This should print one of the following options
# Free Delivery, Standard Delivery, or Receive an email blah blah blah
try:
if "Free Delivery" in x.text:
driver.quit()
file_to_write.close()
return "\t\t[+] Free Delivery"
elif "Get it as soon as tomorrow" in x.text:
driver.quit()
#file_to_write.write("Cell: " + str(cell) + "[*] Express Delivery " + url + '\n')
file_to_write.write("[*] Express Delivery " + url + "\n")
file_to_write.close()
return "\t\t[*] Express Delivery"
elif "Receive an email" in x.text:
driver.quit()
file_to_write("[-] Out of Stock %s\n" % url)
file_to_write.close()
return "\t\t[-] Out of stock!"
elif "Standard Delivery" in x.text:
driver.quit()
file_to_write.close()
return "\t\t[+] Standard Delivery"
except Exception as e:
driver.quit()
print(e)
Home_Depot_Shipping(r"https://www.homedepot.com/p/WEN-8-in-5-Speed-Drill-Press-4208/204853910?keyword=wen+4208")
我希望程序写入文件,如果交货是快递(明天尽快收到)或缺货(收到电子邮件)
只是随机的,我知道 def Home_Depot_Shipping 中的代码应该缩进。它只是不在这里复制。请忽略那个。它适用于免费送货和标准。当它尝试写入文件时,尽管我不断收到此错误
'_io.TextIOWrapper' object is not callable
如有任何建议或帮助,我们将不胜感激! 谢谢
也许你的意思是
file_to_write.write("[-] Out of Stock %s\n" % url)
而不是
file_to_write("[-] Out of Stock %s\n" % url)
作为一般规则,如果您注意,错误消息会得到足够好的提示