Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python selenium从asos中获取数据-需要更好的方法_Python_Selenium_Scrapy_Web Crawler - Fatal编程技术网

python selenium从asos中获取数据-需要更好的方法

python selenium从asos中获取数据-需要更好的方法,python,selenium,scrapy,web-crawler,Python,Selenium,Scrapy,Web Crawler,嗨,我是Python和爬行新手。我一直在研究Stackoverflow,并提出了Python+Selenium来打开Webdriver,打开URL,获取页面源代码,并将其转换为我需要的数据。但是,我知道有一种更好的方法(例如,不使用selenium进行刮取,不必刮取页面源代码,将数据发布到ASP,等等),我希望我可以在这里寻求一些帮助,以达到教育目的 以下是我想要实现的目标 开始: 获取:产品名称、价格、img及其链接 下一页:如果有输出,则转到下一页 在进入我的代码之前,这里是一些背景信

嗨,我是Python和爬行新手。我一直在研究Stackoverflow,并提出了Python+Selenium来打开Webdriver,打开URL,获取页面源代码,并将其转换为我需要的数据。但是,我知道有一种更好的方法(例如,不使用selenium进行刮取,不必刮取页面源代码,将数据发布到ASP,等等),我希望我可以在这里寻求一些帮助,以达到教育目的

以下是我想要实现的目标

  • 开始:
  • 获取:产品名称、价格、img及其链接
  • 下一页:如果有输出,则转到下一页
在进入我的代码之前,这里是一些背景信息。Asos是一个使用分页的站点,因此这与通过多页进行刮取有关。此外,我还尝试在没有硒的情况下将其发布到 根据这些数据:

{'cid':'2623', 'strQuery':"", 'strValues':'undefined', 'currentPage':'0', 
'pageSize':'204','pageSort':'-1','countryId':'10085','maxResultCount':''}
但我得不到回报

我知道我的方法不好,我非常感谢任何帮助/建议/方法/想法!谢谢

import scrapy
import time
import logging

from random import randint
from selenium import webdriver
from asos.items import ASOSItem
from scrapy.selector import Selector
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC



class ASOSSpider(scrapy.Spider):
    name = "asos"
    allowed_domains = ["asos.com"]
    start_urls = [
        "http://www.asos.com/Women/New-In-Clothing/Cat/pgecategory.aspx?cid=2623#/parentID=-1&pge=0&pgeSize=204&sort="

    ]

    def __init__(self):
        self.driver = webdriver.Firefox()

    def parse(self, response):
        self.driver.get(response.url)

        view_204 = self.driver.find_element_by_xpath("//div[@class='product-count-bottom']/a[@class='view-max-paged']")
        view_204.click() #click and show 204 pictures
        time.sleep(5) #wait till 204 images loaded, I've also tried the explicit wait, but i got timedout 
        # element = WebDriverWait(self.driver, 8).until(EC.presence_of_element_located((By.XPATH, "category-controls bottom"))) 
        logging.debug("wait time has reached! go CRAWL!")

        next = self.driver.find_element_by_xpath("//li[@class='page-skip']/a")

        pageSource = Selector(text=self.driver.page_source) # load page source instead, cant seem to crawl the page by just passing the reqular request
        for sel in pageSource.xpath("//ul[@id='items']/li"):
            item = ASOSItem()
            item["product_title"] = sel.xpath("a[@class='desc']/text()").extract()
            item["product_link"] = sel.xpath("a[@class='desc']/@href").extract()
            item["product_price"] = sel.xpath("div/span[@class='price']/text()").extract()
            item["product_img"] = sel.xpath("div/a[@class='productImageLink']/img/@src").extract()
            yield item

        next.click()
        self.driver.close()

似乎是一个更好的职位。你有什么编程问题?既然你要求推荐,我想,你可以通过观看youtube上的Draps教程,特别是基本上关于web刮片的教程,获得一些实用知识。@ChrisP,没有selenium的刮片方法吗?e、 g.通过将此数据集发布到[link]{'cid':'2623','strQuery':'','strValues':'undefined','currentPage':'0','pageSize':'204','pageSort':'-1','countryId':'10085','maxResultCount':''}@3shimi,该模块非常受欢迎,并具有
post
方法。它还可以处理cookies。@谢谢,ChrisP,有没有通过post成功访问这个特定站点的例子?我似乎无法让它发挥作用。这对我来说似乎是一个更好的职位。你有什么编程问题?既然你要求推荐,我想,你可以通过观看youtube上的Draps教程,特别是基本上关于web刮片的教程,获得一些实用知识。@ChrisP,没有selenium的刮片方法吗?e、 g.通过将此数据集发布到[link]{'cid':'2623','strQuery':'','strValues':'undefined','currentPage':'0','pageSize':'204','pageSort':'-1','countryId':'10085','maxResultCount':''}@3shimi,该模块非常受欢迎,并具有
post
方法。它还可以处理cookies。@谢谢,ChrisP,有没有通过post成功访问这个特定站点的例子?我似乎无法让它工作。