Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Modul splinter problem

[es] :: Python :: Modul splinter problem

[ Pregleda: 986 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

milorad
lucic milorad
uzice

Član broj: 8825
Poruke: 485
*.dynamic.sbb.rs.

ICQ: 294798265


Profil

icon Modul splinter problem21.12.2018. u 10:50 - pre 64 meseci
Ako može pomoć ....Ova skripta otvara Chrome i ubacuje u google pretragu primer Blic i treba da izbaci sve linkove , i to sve smešta u exel fajl....međutim problem je što 2 puta to uradi a treći neće pa sve tako
izbaci grešku:

Code:
konacno.py", line 21, in <module>
    search_button.click()
  File "C:\Python27\lib\site-packages\splinter\driver\webdriver\__init__.py", line 634, in click
    self._element.click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
ElementNotVisibleException: Message: element not interactable
  (Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.16299 x86_64)



a skripta je ovako

Code:
from splinter import Browser
import pandas as pd

url = "https://www.google.com"
browser = Browser('chrome')  
browser.visit(url)  

search_bar_xpath = '//*[@id="tsf"]/div[2]/div/div[1]/div/div[1]/input'
search_bar = browser.find_by_xpath(search_bar_xpath)[0]  
search_bar.fill("Developed By Xtream Codes v1.0.60")

search_button_xpath = '//*[@id="tsf"]/div[2]/div/div[2]/div[2]/div/center/input[1]'
search_button = browser.find_by_xpath(search_button_xpath)[0]
search_button.click()
search_results_xpath = '//*[@id="rso"]/div/div/div[1]/div/div/div[1]/a[1]/div/cite'
search_results = browser.find_by_xpath(search_results_xpath) 
scraped_data = []
for search_result in search_results:
    title = search_result.text.encode('utf8')  
    link = search_result["href"]
    scraped_data.append((title, link))
df = pd.DataFrame(data=scraped_data, columns=["title", "link"])
df.to_csv("links.csv")


Pozdrav i Hvala unapred na pomoći
PS : malo da oživimo ovaj podforum
 
Odgovor na temu

python_freak
Aleksa Avramovic

Član broj: 337583
Poruke: 11



+3 Profil

icon Re: Modul splinter problem07.02.2019. u 04:50 - pre 62 meseci
E jbg kako mi promace ovo ? No ipak da ima neki odgovor.

Nemam pojma sto koristis Splinter umesto cistog seleniuma.

Kolko mogu da zakljucim iz tog error-a je da element koji pokusavas da kliknes se trenutno ne nalazi na ekranu.
A ako malo bolje razmislis, ni ti nemozes misem da kliknes na nesto sto se ne nalazi na ekranu.

Tako da u ovom slucaju bi morao da koristis(barem ovo postoji u seleniumu) ActionChains:



Code:


from selenium.webdriver.common import ActionChains  # importujes ActionChains
from selenium import webdriver
import pandas as pd

url = "https://www.google.com"
# ovako se kreira browser u seleniumu
browser = webdriver.Chrome(executable_path='./chromedriver.exe')  # ./chromedriver.exe - ako se driver nalazi u trenutnom direktorijumu
browser.get(url)  # get umesto visit.

search_bar_xpath = '//*[@id="tsf"]/div[2]/div/div[1]/div/div[1]/input'
search_bar = browser.find_element_by_xpath(search_bar_xpath)[0]  # umesto find_by_xpath, selenium ima u nazivu metode jos i element
search_bar.send_keys("Developed By Xtream Codes v1.0.60")           # send_keys umesto fill.

search_button_xpath = '//*[@id="tsf"]/div[2]/div/div[2]/div[2]/div/center/input[1]'
search_button = browser.find_element_by_xpath(search_button_xpath)[0]

### E sad umesto samo da kliknes na search_button, prvo trebas da se fokusiras na njega, pa onda da ga kliknes.
ActionChains(browser).move_to_element(search_button).click().perform()
###

search_results_xpath = '//*[@id="rso"]/div/div/div[1]/div/div/div[1]/a[1]/div/cite'
search_results = browser.find_element_by_xpath(search_results_xpath) 
scraped_data = []
for search_result in search_results:
    title = search_result.text.encode('utf8')  
    link = search_result["href"]
    scraped_data.append((title, link))
df = pd.DataFrame(data=scraped_data, columns=["title", "link"])
df.to_csv("links.csv")

 
Odgovor na temu

[es] :: Python :: Modul splinter problem

[ Pregleda: 986 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.