Start_urls 没有被解析
Start_urls not getting parsed
下面的代码非常接近您在使用 Scrapy's
FormRequest
时在大多数教程中看到的代码,但出于某种原因,无论我尝试什么变体,我似乎都无法做到让它工作。我的理解(也许我完全错了)start_url
应该基本上移交给 parse
函数,该函数开始抓取站点的过程。每当我 运行 这个脚本时,它只是将 start_url
设置为 URL,然后将 parse
视为未调用的函数(跳过它)。我不确定我做错了什么,但这让我抓狂!!
import requests
import scrapy
from scrapy import Spider
from scrapy.http import FormRequest
def authentication_failed(response):
# TODO: Check the contents of the response and return True if it failed
# or False if it succeeded.
pass
class LoginSpider(scrapy.Spider):
name = 'example.com'
start_urls = ["https://app.hubspot.com/login"]
def parse(self, response):
f=open("/PATH/auth.txt","r")
lines=f.readlines()
username=lines[0]
password=lines[1]
f.close()
yield scrapy.FormRequest.from_response(
response,
formdata={'email': username, 'password': password},
callback=self.after_login(self,response)
)
def after_login(self, response):
if authentication_failed(response):
self.logger.error("Login failed")
return
正在传递给解析函数,这是页面:
正在使用 Javascript 检查您的浏览器,请尝试使用无头浏览器。
下面的代码非常接近您在使用 Scrapy's
FormRequest
时在大多数教程中看到的代码,但出于某种原因,无论我尝试什么变体,我似乎都无法做到让它工作。我的理解(也许我完全错了)start_url
应该基本上移交给 parse
函数,该函数开始抓取站点的过程。每当我 运行 这个脚本时,它只是将 start_url
设置为 URL,然后将 parse
视为未调用的函数(跳过它)。我不确定我做错了什么,但这让我抓狂!!
import requests
import scrapy
from scrapy import Spider
from scrapy.http import FormRequest
def authentication_failed(response):
# TODO: Check the contents of the response and return True if it failed
# or False if it succeeded.
pass
class LoginSpider(scrapy.Spider):
name = 'example.com'
start_urls = ["https://app.hubspot.com/login"]
def parse(self, response):
f=open("/PATH/auth.txt","r")
lines=f.readlines()
username=lines[0]
password=lines[1]
f.close()
yield scrapy.FormRequest.from_response(
response,
formdata={'email': username, 'password': password},
callback=self.after_login(self,response)
)
def after_login(self, response):
if authentication_failed(response):
self.logger.error("Login failed")
return
正在传递给解析函数,这是页面:
正在使用 Javascript 检查您的浏览器,请尝试使用无头浏览器。