爬取京东商品信息
爬虫库:selenium、pyquery
数据库:MongoDB
代码如下:
1.spider.py
import time
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
from selenium.webdriver.chrome.options import Options
client=pymongo.MongoClient(MONGO_URL)
db=client[MONGO_DB]
#browser=webdriver.Chrome()
chrome_options = Options()
chrome_options.add_argument('--headless')
browser= webdriver.Chrome(chrome_options = chrome_options)
wait=WebDriverWait(browser, 10)
def search(KeyWord):
try:
browser.get('https://www.jd.com')
input = wait.until(
EC</