【发布时间】:2021-04-15 10:34:49
【问题描述】:
新手程序员,目前正在制作WebCrawler并想出了
driver.close()
^语法错误如下图,
但是,我使用上面的驱动程序没有问题,所以我现在很困惑
感谢我能得到的所有帮助
提前感谢团队
import sys
from selenium import webdriver as wd
# from bs4 import BeautifulSoup as bs
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# import pymysql as my
import time
# from Tour import TourInfo
# First Url =
# https://stamprally.org/?search_keywords=&search_keywords_operator=and&search_cat1=145&search_cat2=0
# Second Url =
# https://stamprally.org/?search_keywords=&search_keywords_operator=and&search_cat1=66&search_cat2=0
driver.get(main_url)
try:
element = WebDriverWait(driver, 10).until(
# 지정한 요소 한개가 발견되면 웨이트 종료
EC.presence_of_element_located((By.ID, 'header_search_cat1'))
)
except Exception as e:
print('오류 발생', e)
driver.implicitly_wait(10)
for prefectureValue in range(66, 121):
offshorePrefectureValue = 145
try:
driver.get(
f"https://stamprally.org/?search_keywords=&search_keywords_operator=and&search_cat1={prefectureValue}&search_cat2=0)")
print(driver.current_url)
# close off
driver.close()
driver.quit()
sys.exit()
SyntaxError: invalid syntax
PS C:\Users\eong\Desktop\stamprally_crawl> python run.py
File "C:\Users\eong\Desktop\stamprally_crawl\run.py", line 70
driver.close()
^
SyntaxError: invalid syntax
【问题讨论】:
标签: python selenium syntax web-crawler