0

I am new to scrapy and using scrapy with python 2.7 for web automation. I want to click on a html button on a website which opens a login form. My problem is that I just want to click on a button and trasfer control to new page. I have read all similar questions but none found satisfactory because they all contain direct login or using selenium.

Below is HTML Code for button and I want to visit http://example.com/login where there is login page.

<div class="pull-left">
    <a href="http://example.com/login" class="emplink">Employers</a>    

I have written code for to extract link. But how to visit that link and carry out next process. Below is My code.

import scrapy

class QuotesSpider(scrapy.Spider):
    name = 'pro'
    url =  "http://login-page.com/"


def start_requests(self):
    yield scrapy.Request(self.url, self.parse_login)


def parse_login(self, response):
    employers = response.css("div.pull-left a::attr(href)").extract_first()
    print employers

Do I need to use "yield" Everytime and callback to new fuction for just visiting a link or there is other way to do it.

1 Answer 1

2

What you need is to yield a new request or easier make a response.follow like in the docs:

def parse_login(self, response):
    next_page = response.css("div.pull-left a::attr(href)").extract_first()
    if next_page is not None:
        yield response.follow(next_page, callback=self.next_page_parse)

About the callback, it depends basically on how easily can the page gets parsed, for example, check the general spiders section on the docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.