我想将元素从Web元素转换为字符串,并将其发送到另一个函数并在文件名中使用它.我试了很多方法,但都失败了.我正在寻找如何做这件事的 idea .在我的代码下面.
product_title = None
def product_title():
global product_title
product_title = driver.find_element(By.CSS_SELECTOR, "#GoodsBlock > table > tbody > tr:nth-child(1) > td.product-title > div > a")
print(product_title.text)
product_title.click()
def write_txt():
file = open("games_files/"+product_title+".txt", "w")
product_title()
write_txt()
和错误
Traceback (most recent call last):
File "D:\python\xbox\pythonProject\scrap_games.py", line 48, in <module>
write_txt()
File "D:\python\xbox\pythonProject\scrap_games.py", line 41, in write_txt
file = open("games_files/"+product_title.text+".txt", "w")
^^^^^^^^^^^^^^^^^^
我试了很多方法,但都失败了.我正在寻找如何做这件事的 idea .