資源簡介
需要下載 chromedriver 放到運行目錄
代碼片段和文件信息
#?配置數(shù)據(jù)庫信息
MONGO_URL?=?‘localhost‘
MONGO_DB?=?‘taobao‘?#?數(shù)據(jù)庫名
MONGO_TABLE?=?‘product‘?#?表名
import?re
from?selenium?import?webdriver
from?selenium.common.exceptions?import?TimeoutException
from?selenium.webdriver.common.by?import?By
from?selenium.webdriver.support.ui?import?WebDriverWait
from?selenium.webdriver.support?import?expected_conditions?as?EC
from?pyquery?import?PyQuery?as?pq
from?config?import?*
import?pymongo
#鏈接數(shù)據(jù)庫
client=pymongo.MongoClient(MONGO_URL)
db?=?client[MONGO_DB]
browser?=?webdriver.Chrome()
wait?=?WebDriverWait(browser?10)
def?search():
????try:
????????browser.get(‘https://www.taobao.com‘)
????????input=?wait.until(
????????????EC.presence_of_element_located((By.CSS_SELECTOR?“#q“))
????????)
????????submit?=wait.until(EC.elemen
評論
共有 條評論