这是我的代码,不确定我在这里做错了什么。谢谢你的帮助
from selenium import webdriver
from bs4 import BeautifulSoup
import scrapy
from scrapy.spiders import Spider
import requests
import time
import xlsxwriter
import pandas as pd
url = 'https://www.ufc.com/athletes/all?filters%5B0%5D=status%3A23'
driver = webdriver.Chrome('/Applications/Python 3.9/chromedriver')
driver.get(url)
class WebSpider(scrapy.spider):
name = "Web_Spider"
allowed_domains = ['https://www.ufc.com/athletes']
start_urls = ['https://www.ufc.com/athletes/all?filters%5B0%5D=status%3A2']
def __init__(self):
self.driver = driver
def parse(self, response):
self.driver.get(response.url)
while True:
next = self.drive.find_element_by_xpath('//*[@id="block-mainpagecontent"]/div/div/div[2]/div/div/ul/li/a')
try:
next.click()
except:
break
self.driver.close()
我一直收到错误'AttributeError:模块'scrapy'没有属性'spider'。不确定在这里要做什么,Scrapy安装正确并且是最新的
根据您要做的事情,我不会在这里使用Selenium,因为您可以直接通过ajax获取数据。硒仍能发挥作用,但它的杀伤力有点过大,效率较低
试试这个:
是刮毛的蜘蛛,大写“s”
相关问题 更多 >
编程相关推荐