Skip to content

Malka yehudit - #2

Open
MalkaYehudit wants to merge 4 commits into
exercisesfrom
malka-yehudit
Open

Malka yehudit#2
MalkaYehudit wants to merge 4 commits into
exercisesfrom
malka-yehudit

Conversation

@MalkaYehudit

Copy link
Copy Markdown
Owner

selenium zap market

Comment thread selenium/shopping_bot.py
from selenium.webdriver.chrome.service import Service

ZAP_MARKET_URL = "https://www.zapmarket.co.il/"
CHROMEDRIVER_PATH = 'C:\Program Files\chromedriver-win64/chromedriver.exe'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ניתוב כזה עובד רק על המחשב שלך, ולא יעבוד למישהו אחר שינסה להריץ.
יש כמה אופציות לפתרון, הדרך המומלצת ביותר היא שימוש ב-webdriver_manager
הספריה webdriver_manager מנהלת הורדה והתקנה של ה-WebDriver המתאים באופן אוטומטי. זה אומר שכל משתמש שמריץ את הקוד לא צריך לדאוג להורדת ChromeDriver ידנית.
הצעדים כדי לעשות את זה:
התקן את הספרייה: pip install webdriver-manager
שנה את הקוד שלך:
במקום לציין נתיב קשיח, השתמש ב-ChromeDriverManager:


from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

 השתמש ב-ChromeDriverManager כדי להוריד ולהגדיר את ה-ChromeDriver
service = ChromeService(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)

Comment thread selenium/zap_market.py

def scroll_to_bottom(self):
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

עדיף להימנע כמה שיותר מtime.sleep()ץ רק במקרים של חוסר ברירה
עדיף שתגדילי את WebDriverWait(self.driver, timeout).until ותוסיפי תנאים

Comment thread selenium/zap_market.py
self.close_promo_if_exists()
self.driver.execute_script("arguments[0].scrollIntoView();", update_button)
self.driver.execute_script("arguments[0].click();", update_button)
time.sleep(1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

כמו בשורה 42

Comment thread selenium/zap_market.py
simplified_name = product_name.split()[0]
best_match, best_ratio = find_best_match(simplified_name)

if not best_match or best_ratio < 0.3:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

יכול להיות ש0.3 מדי נמוך, ניסית להגדיל אותו?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants