Entering an input, clicking it and retrieving particular information with Selenium [on hold]



  • I\'m new to web scraping with Python. My intent is to retrieve the verb for a word of interest. For e.g. dictionary.com has definitions for different parts of speech for word, I would like to enter a word of interest and then hit the search icon, in the resulting page I would like to extract the information under the header \'verb\'.



  • To extract the information under verb header Induce WebDriverWait and presence_of_all_elements_located()

    Here is the code.

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver=webdriver.Chrome()
    driver.get("https://www.dictionary.com/")
    WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//button[contains(.,'Accept Cookies')]"))).click()
    elementsearch=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input[title='Search']")))
    elementsearch.send_keys("interest")
    elementsearch.submit()
    results=WebDriverWait(driver,20).until(EC.presence_of_all_elements_located((By.XPATH,"//span[@class='luna-pos'][contains(.,'verb')]/following::div[1]//div[@class='default-content']//div")))
    for item in results:
        print(item.text)
    
    results1=WebDriverWait(driver,20).until(EC.presence_of_all_elements_located((By.XPATH,"//span[@class='luna-pos'][contains(.,'verb')]/following::div[1]//div[@class='expandable-content']//div")))
    for item in results1:
        print(item.get_attribute("textContent"))
    
    

    Output on console:

    to engage or excite the attention or curiosity of:
    Mystery stories interested him greatly.
    to concern (a person, nation, etc.) in something; involve:
    The fight for peace interests all nations.
    to cause to take a personal concern or share; induce to participate: to interest a person in an enterprise.
    to cause to be concerned; affect.
    
    


最新内容

  • 问题

    I have installed the following in my Windows 10 machine:

    VS Code - version 1.38.1 Golang - version go1.13 Delve - version 1.3.0

    I have set GOROOT and GOPATH in environment variables. My GOPATH has the following three folders:

    src bin pkg

    Under src, I have created a basic sam-app. It auto-creates main_test.go file. When I do \'debug test\', breakpoint is not hitting in UI. Howerver, I am able to debug using dlv in command line.

    I have tried different configurations in launch.json. None of them worked. In my friend\'s machine, the UI Debugging works even without configurations

    In VS Code settings --> node debug --> auto attach --> I have set \'on\'

    I have closed VS Code and re-opened. It did not work

    I have opened VS Code as Administrator, it did\'t work either

    I have uninstalled and reinstalled VS Code

    I have uninstalled and reinstalled Golang

    I have installed Go extension in VS Code

    package main import ( \"fmt\" \"net/http\" \"net/http/httptest\" \"testing\" \"github.com/aws/aws-lambda-go/events\" ) func TestHandler(t *testing.T) { t.Run(\"Unable to get IP\", func(t *testing.T) { DefaultHTTPGetAddress = \"http://127.0.0.1:12345\" _, err := handler(events.APIGatewayProxyRequest{}) if err == nil { t.Fatal(\"Error failed to trigger with an invalid request\") } }) t.Run(\"Non 200 Response\", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err != nil && err.Error() != ErrNon200Response.Error() { t.Fatalf(\"Error failed to trigger with an invalid HTTP response: %v\", err) } }) t.Run(\"Unable decode IP\", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err == nil { t.Fatal(\"Error failed to trigger with an invalid HTTP response\") } }) t.Run(\"Successful Request\", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) fmt.Fprintf(w, \"127.0.0.1\") })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err != nil { t.Fatal(\"Everything should be ok\") } }) }

    I want the breakpoint to be hit, in UI, when I debug main.go or main_test.go.

    UPDATE:

    After I downgraded my VS Code to 1.30.2 and installed Go extension and Delve, I get the following error when I debug:

    \"Debug adapter process has terminated unexpectedly (read error)\"

    回答1:

    0

    I solved it as follows:

    Deleted the '%USERPROFILE%\.vscode\extensions\ms-vscode.go-0.11.4' folder alone & reinstalled Go extension -- It did NOT work Deleted the entire '%USERPROFILE%\.vscode' folder & reinstalled Go extension -- It worked 🙂

    Some other extension was erroneous and so the Go debug failed to work. Cleaning all the extensions fixed it.

    Hope, this might be useful to others.

    share|improve this answer

    edited Sep 14 at 11:46

    answered Sep 14 at 11:36

    MAKMAK 1011010 bronze badges

    add a comment |

    read more
  • 殿

    I solved it as follows:

    Deleted the '%USERPROFILE%\.vscode\extensions\ms-vscode.go-0.11.4' folder alone & reinstalled Go extension -- It did NOT work Deleted the entire '%USERPROFILE%\.vscode' folder & reinstalled Go extension -- It worked 🙂

    Some other extension was erroneous and so the Go debug failed to work. Cleaning all the extensions fixed it.

    Hope, this might be useful to others.

    read more
  • I have installed the following in my Windows 10 machine:

    VS Code - version 1.38.1 Golang - version go1.13 Delve - version 1.3.0

    I have set GOROOT and GOPATH in environment variables. My GOPATH has the following three folders:

    src bin pkg

    Under src, I have created a basic sam-app. It auto-creates main_test.go file. When I do \'debug test\', breakpoint is not hitting in UI. Howerver, I am able to debug using dlv in command line.

    I have tried different configurations in launch.json. None of them worked. In my friend\'s machine, the UI Debugging works even without configurations

    In VS Code settings --> node debug --> auto attach --> I have set \'on\'

    I have closed VS Code and re-opened. It did not work

    I have opened VS Code as Administrator, it did\'t work either

    I have uninstalled and reinstalled VS Code

    I have uninstalled and reinstalled Golang

    I have installed Go extension in VS Code

    package main import ( \"fmt\" \"net/http\" \"net/http/httptest\" \"testing\" \"github.com/aws/aws-lambda-go/events\" ) func TestHandler(t *testing.T) { t.Run(\"Unable to get IP\", func(t *testing.T) { DefaultHTTPGetAddress = \"http://127.0.0.1:12345\" _, err := handler(events.APIGatewayProxyRequest{}) if err == nil { t.Fatal(\"Error failed to trigger with an invalid request\") } }) t.Run(\"Non 200 Response\", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err != nil && err.Error() != ErrNon200Response.Error() { t.Fatalf(\"Error failed to trigger with an invalid HTTP response: %v\", err) } }) t.Run(\"Unable decode IP\", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err == nil { t.Fatal(\"Error failed to trigger with an invalid HTTP response\") } }) t.Run(\"Successful Request\", func(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) fmt.Fprintf(w, \"127.0.0.1\") })) defer ts.Close() DefaultHTTPGetAddress = ts.URL _, err := handler(events.APIGatewayProxyRequest{}) if err != nil { t.Fatal(\"Everything should be ok\") } }) }

    I want the breakpoint to be hit, in UI, when I debug main.go or main_test.go.

    UPDATE:

    After I downgraded my VS Code to 1.30.2 and installed Go extension and Delve, I get the following error when I debug:

    \"Debug adapter process has terminated unexpectedly (read error)\"

    read more

最新主题

推荐阅读

本站部分内容来自互联网,其发布内容言论不代表本站观点,如果其链接、内容的侵犯您的权益,烦请联系我们,我们将及时予以处理。
Powered by NodeBB | 备案号:宁ICP备15000671号