[英]i have a problem with my code with StringsProperty
我的代码中有错误,我知道错误是什么,但我不知道如何修复它。
这是我的代码:
值:
<Main>
product: product
Screen:
BoxLayout:
size_hint: .8, .8
pos_hint: {"center_x": .5, "y": .7}
spacing: dp(100)
orientation: "vertical"
MDTextFieldRound:
id: product
hint_text: 'Enter a product'
icon_left: 'magnify'
on_text_validate: app.System()
FloatLayout:
MDCard:
orientation: "vertical"
size_hint: .43, .3
height: self.minimum_height
pos_hint: {"x": .05, "y": .35}
BoxLayout:
id: box
size_hint_y: None
height: dp(150)
MDLabel:
text: app.Ebay_text
派:
class Main(MDApp):
Window.size = (310, 520)
title = "Best Price"
def build(self):
return Builder.load_string(KV)
product = ObjectProperty(None)
Ebay_text = StringProperty()
def System(self):
self.options = webdriver.ChromeOptions()
self.options.add_argument('headless')
self.options.add_argument('window-size=1920x1080')
self.options.add_argument("disable-gpu")
self.browser =
webdriver.Chrome('C://Users//Yesnia//Documents//chromedriver_win32//chromedriver.exe',
options=self.options)
self.browser.get('https://www.ebay.com/')
self.Esearch = self.browser.find_element_by_name('_nkw')
self.Esearch.send_keys(self.root.ids.product.text)
self.Esearch.send_keys(Keys.ENTER)
self.url = self.browser.current_url
self.browser.get('https://www.bestbuy.com.mx/')
self.Bsearch = self.browser.find_element_by_id('gh-search-input')
self.Bsearch.send_keys(self.root.ids.product.text)
self.Bsearch.send_keys(Keys.ENTER)
self.url1 = self.browser.current_url
#Ebay extractor
self.Ebay = Extractor.from_yaml_file('ebay.txt')
self.r_ebay = requests.get(self.url)
self.data_ebay = self.Ebay.extract(self.r_ebay.text)
#bestbuy extractor
self.Bestbuy = Extractor.from_yaml_file('Bestbuy.txt')
self.r_bestbuy = requests.get(self.url1)
self.data_bestbuy = self.Bestbuy.extract(self.r_bestbuy.text)
print('Product ', self.root.ids.product.text)
print('Ebay: ', self.data_ebay)
print('Bestbuy: ', self.data_bestbuy)
self.Ebay_text = self.data_ebay
if __name__ == "__main__":
Main().run()
这是错误:
self.Ebay_data = self.data_ebay
File "kivy\properties.pyx", line 497, in
kivy.properties.Property.__set__
File "kivy\properties.pyx", line 541, in kivy.properties.Property.set
File "kivy\properties.pyx", line 532, in kivy.properties.Property.set
File "kivy\properties.pyx", line 698, in
kivy.properties.StringProperty.check
ValueError: Main.Ebay_data accept only str
我知道问题在于,如果我将 stringProperty 赋予文本,它必须与“此处有一些文本”一起使用,但是是否有解决方案可以使其正常工作但具有相同的功能?
问题是 StringProperty 只接受 str(),你可以做的是:
Python:
self.data_bestbuy = str(self.Bestbuy.extract(self.r_bestbuy.text))
有了这个,你现在给变量一个 str 属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.