Not able to Login this website https://www.bestpricewholesale.co.in/Registration/login.aspx in python scrapy project

倖福魔咒の 提交于 2019-12-12 02:55:20

问题


Not able to Login only this website in python scrapy project. I want to scrap a login require website and i have already login many websites in my project but not able to Login only this website in python scrapy project.I think i have problem in form response it's """Return the most likely field names for username and password""" but i am not sure and not able to solve this issue

from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.spiders.init import InitSpider
from scrapy.http import Request, FormRequest
from scrapy.contrib.spiders import Rule
from scraping.articles import ArticleItem
from scrapy.spider import BaseSpider
from scrapy import log

class BestPriceGetCatUrl(InitSpider,BaseSpider):
    name = "BestPriceGetCatUrl"
    allowed_domains = ["bestpricewholesale.co.in"]
    login_page = 'https://www.bestpricewholesale.co.in/Registration/login.aspx'
    start_urls = ["http://www.bestpricewholesale.co.in/categories/Apparel--Home/cid-CK00002496.aspx"]

    def start_requests(self):
        return self.init_request()

    def init_request(self):
        return [Request(url=self.login_page, callback=self.login)]

    def login(self, response):
        log.msg("hello i am here in login....")
        #args, url, method = fill_login_form(response.url, response.body, self.login_user, self.login_pass)
        #return FormRequest(url, method=method, formdata=args, callback=self.check_login_response)
        return FormRequest.from_response(response, formdata={'ctl00$ContentPlaceHolder1$ctl00$ctl01$Login1$UserName': 'username', 'ctl00$ContentPlaceHolder1$ctl00$ctl01$Login1$Password': 'passward'}, callback=self.check_login_response)

    def check_login_response(self, response):
        log.msg("in check login response : "+str(response))
        if "Logout" in response.body:
            for url in self.start_urls:
                nUrl = self.make_requests_from_url(url)
                yield Request("http://www.bestpricewholesale.co.in/categories/Apparel--Home/cid-CK00002496.aspx",callback=self.parseItems)
        else:
            self.log("Could not log in...")

    def parseItems(self, response):
        item = ArticleItem()
        item['title'] = "ranvijay"
        log.msg("***************    :   "+str(response.xpath("//*[@id='lblUserName']/label[@id='lblusrN']/text()").extract()))
        item['url'] = response.xpath("//*[@id='lblusrN']/text()").extract()
        item['name1'] = response.xpath("//*[@id='ctl00_ContentPlaceHolder1_ctl00_ctl01_lblUserName']/text()").extract()
        yield item

from scrapy.item import Item, Field

class ArticleItem(Item):
    title = Field()
    url = Field()
    name1 = Field()

来源:https://stackoverflow.com/questions/27313663/not-able-to-login-this-website-https-www-bestpricewholesale-co-in-registration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!