【问题标题】:Scrapy downloads the HTML template rather than the page sourceScrapy 下载 HTML 模板而不是页面源
【发布时间】:2021-09-15 01:55:10
【问题描述】:

我是 Scrapy 的新手,所以请原谅这个愚蠢的问题。

import scrapy
from bs4 import BeautifulSoup
from scrapy_proj.scrapy_proj.items import PageSourceLoc, ItemField
from scrapy.loader import ItemLoader
from scrapy.http.response import Response
from scrapy import Selector


class MySpider(scrapy.Spider):
    name = 'websources'
    start_urls = ["https://www.acquistinretepa.it/opencms/opencms/scheda_altri_bandi.html?idBando=b11f430208bfa91e"]

    def parse(self, response: Response, **kwargs):
        page_info = PageSourceLoc()
        soup = BeautifulSoup(response.body, 'html.parser')
        print(response.text)

说到查看页面的详细信息,我发现与使用的模板相关的元素,例如:

{{numeroVerdePA}}, {{numeroVerdeIM}}

那些应该已经填充了网页的当前值。我是否缺少一些 Scrapy 设置?

谢谢

【问题讨论】:

    标签: python html templates scrapy


    【解决方案1】:

    我想通了。当发生此类连线错误时,您只需使用 Selenium (https://github.com/clemfromspace/scrapy-selenium) 并相应地解析页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2012-11-03
      • 2015-10-22
      相关资源
      最近更新 更多