3
\$\begingroup\$

I'm making a scraper/web crawler using Kivy when I run the code it works but I'm not sure if what I'm doing is Pythonic because all the language I can find is about using the Kivy library. I'm unsure about putting the functions to bind the widgets to inside the build method. Is there a better way?

class MainApp(App):

    def build(self):
        root = RootWidget()
        c = CustomLayout()
        root.add_widget(c)

        search_term = TextInput(
            text='',
            size_hint=(.5, .05),
            pos=(250, 15))
        c.add_widget(search_term)

        def on_enter(self):
            scrape = Scrape(search_term.text, ['user_agent','chrome'])
            scrape.get_goog_links()
        get_links = Button(
            text='Get links',
            size_hint=(.5, .10),
            pos=(20, 20))
        root.add_widget(get_links)
        get_links.bind(on_press=on_enter)

        return root
\$\endgroup\$
  • \$\begingroup\$ You know Google has bot protection against this kind of thing, right? \$\endgroup\$ – Quill Feb 2 '16 at 22:33
  • \$\begingroup\$ @Quill It still works though ;). \$\endgroup\$ – Eric MacLeod Feb 2 '16 at 22:36
  • \$\begingroup\$ Not saying it doesn't, just might not be effective when you ramp up the speeds. \$\endgroup\$ – Quill Feb 2 '16 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.