1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] playwright scrapy cant login to site but just plawright is do

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I want to login with scrapy_playwright in scrapy spider but it says incorrect login information but when i try to login with just playwrigt ans without scrapy it can login.

    There can be diffrents from scrapy code inputs and playwright code inputs but think about them same credentials. It just changed for prevent data leak in code. This is my spider:


    class BiosSpider(scrapy.Spider):
    name = "bios"

    def start_requests(self):


    yield (scrapy.Request(url="https://mysite.com.tr/LoginPage",
    callback=self.parse,

    meta={"playwright": True,
    "playwright_include_page": True,
    "playwright_page_methods": [

    PageMethod(
    "fill", '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/div/input[@name="bayiKodu"]', value="aaaaa"),


    PageMethod(
    "fill", '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/div/input[@name="kullaniciAdi"]', value="aaaaaab"),

    PageMethod(
    "fill", '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/div/input[@name="sifre"]', value="ccccccc"),
    PageMethod(
    "wait_for_timeout", 5*1000),

    PageMethod(
    "click", '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/button'),


    ]

    }))

    async def parse(self, response):
    print("QQQQQQQQQ", response)
    print("UUUUUUUUUU", response.request.headers['User-Agent'])
    print("HHHHHHHHHHH", response.request.headers)
    page = response.meta['playwright_page']


    await page.wait_for_timeout(50*1000)


    But when i use just playwright i can login : This is just playwright

    from playwright.sync_api import sync_playwright


    with sync_playwright() as p:
    bwo = p.chromium.launch(headless=False, slow_mo=50)
    page = bwo.new_page()
    page.goto("https://mysite.com.tr/LoginPage")
    page.locator(
    '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/div/input[@name="bayiKodu"]'
    ).fill("aaaa"),
    page.locator(
    '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/div/input[@name="kullaniciAdi"]').fill("bbbbbb")
    page.locator(
    '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/div/input[@name="sifre"]').fill("ccccccc")
    page.locator(
    '//div[@class="card-body"]/form[@id="uyeGirisFormBayi"]/button').click()
    page.wait_for_timeout(500*1000)
    page.close()



    There is no error turn back for scrapy my settings :


    USER_AGENT = None
    REQUEST_FINGERPRINTER_IMPLEMENTATION = "2.7"
    TWISTED_REACTOR = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
    FEED_EXPORT_ENCODING = "utf-8"


    PLAYWRIGHT_LAUNCH_OPTIONS = {"headless": False}

    DOWNLOAD_HANDLERS = {
    "http": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
    "https": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
    }
    TWISTED_REACTOR = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"

    # timeout zamanı
    PLAYWRIGHT_DEFAULT_NAVIGATION_TIMEOUT = 600*1000



    i downt know what i'm missing please hep me

    for fill the question :

    Continue reading...

Compartilhe esta Página