使用帖子方法刮擦多​​个页面

发布于 2025-02-13 13:55:00 字数 2419 浏览 0 评论 0 原文

import scrapy
from scrapy.http import Request
from scrapy.selector import Selector
from selenium import webdriver
import time
from scrapy_selenium import SeleniumRequest


class TestSpider(scrapy.Spider):
    name = 'test'
    
    url = "https://www.benrishi-navi.com/english/english1_3.php"

    payload='serial=19&office_serial=&submit2=Details'
    headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8,pt;q=0.7',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Cookie': 'CAKEPHP=u6u40lefkqnm45j49a5i0h6bs3',
    'Origin': 'https://www.benrishi-navi.com',
    'Referer': 'https://www.benrishi-navi.com/english/english1_2.php',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
    'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"'
    }

    def start_requests(self):
         yield SeleniumRequest(
            url=self.url,
            method='POST',
            body=self.payload,
            wait_time=3,
            screenshot=True,
            headers=self.headers,
            callback=self.parse,
            dont_filter=True,
        )

    def parse(self,response):
          title=response.xpath("//td[@class='kiso']//text()").getall()
          print(title)

我使用帖子方法从页面上删除数据,但是每个数据都有不同的序列号这些是页面链接 https://www.benrishi-navi.com/english/english/english1_2.php

然后使用邮政方法从这些页面中获取请求,但每个数据都有不同的序列序列号码转到有效载荷,每个页面都有与我刮擦多个页面的序列号不同,因为每个数据都有不同的序列号

import scrapy
from scrapy.http import Request
from scrapy.selector import Selector
from selenium import webdriver
import time
from scrapy_selenium import SeleniumRequest


class TestSpider(scrapy.Spider):
    name = 'test'
    
    url = "https://www.benrishi-navi.com/english/english1_3.php"

    payload='serial=19&office_serial=&submit2=Details'
    headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8,pt;q=0.7',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Cookie': 'CAKEPHP=u6u40lefkqnm45j49a5i0h6bs3',
    'Origin': 'https://www.benrishi-navi.com',
    'Referer': 'https://www.benrishi-navi.com/english/english1_2.php',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
    'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"'
    }

    def start_requests(self):
         yield SeleniumRequest(
            url=self.url,
            method='POST',
            body=self.payload,
            wait_time=3,
            screenshot=True,
            headers=self.headers,
            callback=self.parse,
            dont_filter=True,
        )

    def parse(self,response):
          title=response.xpath("//td[@class='kiso']//text()").getall()
          print(title)

I am scraping the data from the page using the post method but every data has different serial number these is page link https://www.benrishi-navi.com/english/english1_2.php

enter image description here

Then using the post method to get request from these page but every data has different serial number go to payload and every page has different serial number than how I scrape multiple page because every data has different serial number
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文