Spaces:
Sleeping

File size: 1,967 Bytes
76a7948
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLineEdit, QVBoxLayout, QWidget
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

class WikiScraper(QMainWindow):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        # Create a textbox
        self.textBox = QLineEdit(self)
        self.textBox.setPlaceholderText("Type search term here...")

        # Create a button in the window
        self.button = QPushButton('Go to wiki', self)
        self.button.clicked.connect(self.on_click)

        # set the layout
        layout = QVBoxLayout()
        layout.addWidget(self.textBox)
        layout.addWidget(self.button)

        container = QWidget()
        container.setLayout(layout)
        self.setCentralWidget(container)

        self.setWindowTitle('Wiki Searcher')
        self.setGeometry(300, 300, 350, 200)

    def on_click(self):
        searchTerm = self.textBox.text()
        if searchTerm:
            driver.get("https://www.wikipedia.org/")
            searchBox = driver.find_element(By.NAME, "search")
            searchBox.clear()
            searchBox.send_keys(searchTerm)
            searchBox.send_keys(Keys.RETURN)
            # Now the search is done, you could continue to scrape results if needed
            # Here an example of copying first heading from the results
            firstHeading = driver.find_element(By.ID, "firstHeading")
            self.textBox.setText(firstHeading.text)

if __name__ == '__main__':
    # Set up the Selenium driver for Chrome
    options = webdriver.ChromeOptions()
    options.add_argument('headless')
    driver_path = '/path/to/chromedriver' # Update this to your Chromedriver path
    driver = webdriver.Chrome(driver_path, options=options)

    app = QApplication(sys.argv)
    ex = WikiScraper()
    ex.show()
    sys.exit(app.exec_())