Слияние селена со скрапом со страницей входа - PullRequest
0 голосов
/ 19 апреля 2020

Я использовал селен, чтобы пройти страницу входа и страницу, на которой вы должны принять условия использования этой страницы. Однако я хочу включить Scrapy для очищающей части и сохранить ее как файл .db, чтобы использовать его в SQLITE3, я знаю, как сохранить его как файл .db, но объединяя их; Селен и скрап не работают для меня ... Любая помощь подойдет!

import scrapy
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import copy
from ..items import googleItem

#Section 1: Logging into page* and navigating to the list of all companies

print('start')

username = input("Insert username: ")
password = input("Insert password: ")
url = "Start_url"

#Open Chrome
driver = webdriver.Chrome()
driver.get(url)
driver.maximize_window()

#Logg in using info in "username" and "password"
driver.find_element_by_name("username").send_keys(username)
driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_name("wp-submit").send_keys(Keys.ENTER)

#Accepting the conditions
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//input[@type="image"]                
[@src="SiteCommon2006/en/Bluef"]'))).click()

#Waiting for the advanced button to fully generate and click it
time.sleep(2)
driver.find_element_by_id("ContentContainer1_ctl00_Content").click()

#Open the dropdown menu by hovering and click the "All deals"-button that appears, then get list

#Really struggled here

element_to_hover_over = driver.find_element_by_xpath('//*        
[@id="ContentContainer1_Content__SearchSearchMenu"]/li[13]')
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
all_deals_button = driver.find_element_by_xpath('//*[@id="ContentContainer1_ctl00_Content').click()
driver.find_element_by_xpath( '//*[@id="ContentContainer1_ctl00_Content"]').click()

#Enter deal
driver.find_element_by_xpath(
'//*[@id="ContentContainer1_ctl00"]/tbody/tr[2]/td[9]/a').click()


class googleSpider(scrapy.Spider):
name = 'google'
allowed_domains = ['Real_url']
start_urls = ['new url']

def parse(self, response):
    all_div_deal = response.css("div.deal")

    for deal in all_div_deal:
        companies = deal.xpath("span.text::text").extract()
        price = deal.xpath(".price::text").extract()
        deal_nr = deal.xpath(".deal_nr::text").extract()

        items['companies'] = companies
        items['price'] = price
        items['deal_nr'] = deal_nr
        yield items
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...