scrapy 相关问题

Scrapy是一个用Python编写的快速开源高级屏幕抓取和Web爬行框架,用于抓取网站并从其页面中提取结构化数据。它可用于各种用途,从数据挖掘到监控和自动化测试。

从调用API的网页获取进行API调用所需的信息

我想从以下网页中提取评级元素: 接下来是哪个代码: 我想从以下网页中提取评级元素: 下一个是哪个代码: <ol data-bv-v="contentItemCollection:2" class="bv-content-list bv-content-list-reviews"> <li data-bv-v="contentItem:9" class="bv-content-item bv-content-top-review bv-content-review bv-content-loaded" itemprop="review" itemscope="" itemtype="http://schema.org/Review" data-content-id="Reviews-158638580"> <div data-bv-v="inlineProfile:13" class="bv-author-profile"> <div class="bv-inline-profile"> <div class="bv-author-avatar"> <div class="bv-author-avatar-nickname"> <div class="bv-content-author-name" role="presentation"> <button type="button" class="bv-author bv-fullprofile-popup-target bv-focusable" aria-label="Voir le profil de oceaned03."> <h3>oceaned03</h3> </button> </div> </div> </div> <div class="bv-popup-prosnap-userinfo bv-contains-profile-button"> <div class="bv-content-author-name" role="presentation"> <button type="button" class="bv-author bv-fullprofile-popup-target bv-focusable" aria-label="Voir le profil de oceaned03."> <h3>oceaned03</h3> </button> </div> <div class="bv-author-location"> <span> Clermont Ferrand </span> </div> <div class="bv-author-userstats"> <ul class="bv-author-userstats-list" role="list"> <li class="bv-author-userstats-reviews"> <span class="bv-author-userstats-data"> Avis : </span> <span class="bv-author-userstats-value">1</span> </li> <li class="bv-author-userstats-votes"> </li> </ul> </div> <div class="bv-content-author-badges"> <ul class="bv-content-author-badges-list" role="presentation"> </ul> </div> <div class="bv-author-userinfo"> <ul role="list"> <li class="bv-author-cdv bv-first "> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Sexe </span> <span class="bv-author-userinfo-value">une femme</span> </li> <li class="bv-author-cdv "> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Age</span> <span class="bv-author-userinfo-value">18-24 ans</span> </li> <li class="bv-author-cdv "> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Couleur des yeux</span> <span class="bv-author-userinfo-value">Bleus</span> </li> <li class="bv-author-cdv bv-last"> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Type de peau</span> <span class="bv-author-userinfo-value">Sèche</span> </li> </ul> </div> </div> </div> </div> <div class="bv-content-item-author-profile-offset bv-content-item-author-profile-offset-on"> <div class="bv-content-container"> <div class="bv-content-core "> <div class="bv-content-header"> <div class="bv-content-data-summary"> <div class="bv-content-badges-container"> <ul class="bv-badge-summary bv-badge-first bv-badge-top-three" role="presentation"> <li class="bv-badge-image bv-badge-content-loyaltyyes--im-a-beauty-insider" role="presentation"> <img src="https://display.ugc.bazaarvoice.com/static/Sephora-FR/main_site/951/3232/fr_FR/images/badgeImages/loyaltyyes--im-a-beauty-insider.png" alt="Carte White" title="Carte White"> </li> </ul> </div> <div class="bv-content-header-meta"> <span class="bv-content-rating bv-rating-ratio" itemprop="reviewRating" itemscope="" itemtype="http://schema.org/Rating"> <meta itemprop="ratingValue" content="5"> <meta itemprop="bestRating" content="5"> <span class="bv-rating-stars-container"> <abbr title="5 sur 5 étoiles." class="bv-rating bv-rating-stars bv-rating-stars-off" aria-hidden="true"> ★★★★★ </abbr> <abbr title="5 sur 5 étoiles." class="bv-rating-max bv-rating-stars bv-rating-stars-on bv-width-from-rating-stats-100" aria-hidden="true"> ★★★★★ </abbr> <span class="bv-off-screen">5 sur 5 étoiles.</span> </span> </span> <div class="bv-content-meta-wrapper"> <div class="bv-content-meta" role="presentation"> <div class="bv-content-reference-data bv-content-author-name"> <button type="button" class="bv-author bv-fullprofile-popup-target bv-focusable" aria-label="Voir le profil de oceaned03." itemprop="author"> <h3>oceaned03</h3> </button> <div class="bv-content-datetime" role="presentation"> <meta itemprop="dateCreated" content="2020-06-24"> <meta itemprop="datePublished" content="2020-06-24"> <span class="bv-content-datetime-dot" aria-hidden="true">·</span> <span class="bv-content-datetime-stamp">il y a 5 mois &nbsp;</span> </div> </div> </div> </div> </div> <div class="bv-content-title-container"> <h3 class="bv-content-title" itemprop="headline"> Satisfaite </h3> </div> </div> </div> <div class="bv-content-details-offset-off"> <div class="bv-content-summary"> <div class="bv-content-summary-body" itemprop="reviewBody"> <div class="bv-content-summary-body-text"> <p>Très contente de mon achat. Je cherchais ce parfum depuis un temps en magasin et je suis heureuse qu’il soit disponible en ligne il sent tellement bon !! En plus en promo, génial ! <br>Livraison très rapide !</p> </div> <div class="bv-content-data"> <div class="bv-content-product-questions"> </div> <div class="bv-content-tag-dimensions"> </div> <ul class="bv-content-data-recommend-yes"> <li class="bv-content-data-label-container"> <span class="bv-content-data-icon" aria-hidden="true">✔</span> <span class="bv-content-data-label">Oui</span>, </li> <li class="bv-content-data-value"> je recommande ce produit. </li> </ul> </div> </div> </div> </div> </div> </div> <div class="bv-content-actions-container bv-active-feedback"> <div data-bv-v="feedback:12" class="bv-feedback-container"> <div class="bv-content-feedback-vote bv-content-feedback-vote-active" role="group" aria-label="Utilité du contenu"> <div class="bv-content-feedback-vote-request"> <p>Avez-vous trouvé cet avis utile ?</p> </div> <div class="bv-content-feedback-btn-container"> <button type="button" class="bv-content-btn bv-content-btn-feedback-yes bv-focusable" aria-label="1&nbsp;personne a trouvé cet avis utile. Oui, review de oceaned03 est utile."> <span aria-hidden="true"> Oui · <span class="bv-content-btn-count" aria-hidden="true">1</span> </span> </button> <button type="button" class="bv-content-btn bv-content-btn-feedback-no bv-focusable" aria-label="0&nbsp;personne a trouvé cet avis inutile. Non, review de oceaned03 n'est pas utile."> <span aria-hidden="true"> Non · <span class="bv-content-btn-count" aria-hidden="true">0</span> </span> </button> </div> <div class="bv-content-feedback-vote bv-content-feedback-vote-active"> <button type="button" class="bv-content-report-btn bv-focusable" aria-label="Marquer «&nbsp;Satisfaite&nbsp;» de oceaned03 comme inapproprié."> Signalez un contenu inapproprié </button> </div> </div> </div> </div> <div class="bv-inline-form-container"></div> <div data-bv-v="secondaryContentList:10" class="bv-secondary-content-list"> <ol data-bv-v="secondaryContentItemCollection:11" class="bv-content-list bv-content-list-clientresponses" role="presentation"> </ol> </div> </div> </li> <li data-bv-v="contentItem:14" class="bv-content-item bv-content-top-review bv-content-review bv-content-loaded" itemprop="review" itemscope="" itemtype="http://schema.org/Review" data-content-id="Reviews-156726085"> <div data-bv-v="inlineProfile:18" class="bv-author-profile"> <div class="bv-inline-profile"> <div class="bv-author-avatar"> <div class="bv-author-avatar-nickname"> <div class="bv-content-author-name" role="presentation"> <button type="button" class="bv-author bv-fullprofile-popup-target bv-focusable" aria-label="Voir le profil de Jo56."> <h3>Jo56</h3> </button> </div> </div> </div> <div class="bv-popup-prosnap-userinfo bv-contains-profile-button"> <div class="bv-content-author-name" role="presentation"> <button type="button" class="bv-author bv-fullprofile-popup-target bv-focusable" aria-label="Voir le profil de Jo56."> <h3>Jo56</h3> </button> </div> <div class="bv-author-location"> <span> Lorient </span> </div> <div class="bv-author-userstats"> <ul class="bv-author-userstats-list" role="list"> <li class="bv-author-userstats-reviews"> <span class="bv-author-userstats-data"> Avis : </span> <span class="bv-author-userstats-value">3</span> </li> <li class="bv-author-userstats-votes"> </li> </ul> </div> <div class="bv-content-author-badges"> <ul class="bv-content-author-badges-list" role="presentation"> </ul> </div> <div class="bv-author-userinfo"> <ul role="list"> <li class="bv-author-cdv bv-first "> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Sexe </span> <span class="bv-author-userinfo-value">une femme</span> </li> <li class="bv-author-cdv "> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Age</span> <span class="bv-author-userinfo-value">18-24 ans</span> </li> <li class="bv-author-cdv "> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Couleur des yeux</span> <span class="bv-author-userinfo-value">Marrons</span> </li> <li class="bv-author-cdv bv-last"> <!-- UIA-7763 - removed default display so only translated strings matched by FB will display; can't remove defaultDisplay field entirely due to compilation errors, so used a value of '' --> <span class="bv-author-userinfo-data">Type de peau</span> <span class="bv-author-userinfo-value">Sèche</span> </li> </ul> </div> </div> </div> </div> <div class="bv-content-item-author-profile-offset bv-content-item-author-profile-offset-on"> <div class="bv-content-container"> <div class="bv-content-core "> <div class="bv-content-header"> <div class="bv-content-data-summary"> <div class="bv-content-badges-container"> <ul class="bv-badge-summary bv-badge-first bv-badge-top-three" role="presentation"> <li class="bv-badge-image bv-badge-content-loyaltyyes--im-a-vib-rouge" role="presentation"> <img src="https://display.ugc.bazaarvoice.com/static/Sephora-FR/main_site/951/3232/fr_FR/images/badgeImages/loyaltyyes--im-a-vib-rouge.png" alt="Carte Gold" title="Carte Gold"> </li> </ul> </div> <div class="bv-content-header-meta"> <span class="bv-content-rating bv-rating-ratio" itemprop="reviewRating" itemscope="" itemtype="http://schema.org/Rating"> <meta itemprop="ratingValue" content="5"> <meta itemprop="bestRating" content="5"> <span class="bv-rating-stars-container"> <abbr title="5 sur 5 étoiles." class="bv-rating bv-rating-stars bv-rating-stars-off" aria-hidden="true"> ★★★★★ </abbr> <abbr title="5 sur 5 étoiles." class="bv-rating-max bv-rating-stars bv-rating-stars-on bv-width-from-rating-stats-100" aria-hidden="true"> ★★★★★ </abbr> <span class="bv-off-screen">5 sur 5 étoiles.</span> </span> </span> <div class="bv-content-meta-wrapper"> <div class="bv-content-meta" role="presentation"> <div class="bv-content-reference-data bv-content-author-name"> <button type="button" class="bv-author bv-fullprofile-popup-target bv-focusable" aria-label="Voir le profil de Jo56." itemprop="author"> <h3>Jo56</h3> </button> <div class="bv-content-datetime" role="presentation"> <meta itemprop="dateCreated" content="2020-05-22"> <meta itemprop="datePublished" content="2020-05-22"> <span class="bv-content-datetime-dot" aria-hidden="true">·</span> <span class="bv-content-datetime-stamp">il y a 6 mois &nbsp;</span> </div> </div> </div> </div> </div> <div class="bv-content-title-container"> <h3 class="bv-content-title" itemprop="headline"> Excellent </h3> </div> </div> </div> <div class="bv-content-details-offset-off"> <div class="bv-content-summary"> <div class="bv-content-summary-body" itemprop="reviewBody"> <div class="bv-content-summary-body-text"> <p>J’adore les parfums de cette marque car je trouve qu’ils sont captivant et surtout ils tiennent toute la journée ! Ils ont des odeurs originales et que l’on ne retrouve pas partout ! Je conseil fortement</p> </div> <div class="bv-content-data"> <div class="bv-content-product-questions"> </div> <div class="bv-content-tag-dimensions"> </div> <ul class="bv-content-data-recommend-yes"> <li class="bv-content-data-label-container"> <span class="bv-content-data-icon" aria-hidden="true">✔</span> <span class="bv-content-data-label">Oui</span>, </li> <li class="bv-content-data-value"> je recommande ce produit. </li> </ul> </div> </div> </div> </div> </div> </div> <div class="bv-content-actions-container bv-active-feedback"> <div data-bv-v="feedback:17" class="bv-feedback-container"> <div class="bv-content-feedback-vote bv-content-feedback-vote-active" role="group" aria-label="Utilité du contenu"> <div class="bv-content-feedback-vote-request"> <p>Avez-vous trouvé cet avis utile ?</p> </div> <div class="bv-content-feedback-btn-container"> <button type="button" class="bv-content-btn bv-content-btn-feedback-yes bv-focusable" aria-label="2&nbsp;personnes ont trouvé cet avis utile. Oui, review de Jo56 est utile."> <span aria-hidden="true"> Oui · <span class="bv-content-btn-count" aria-hidden="true">2</span> </span> </button> <button type="button" class="bv-content-btn bv-content-btn-feedback-no bv-focusable" aria-label="0&nbsp;personne a trouvé cet avis inutile. Non, review de Jo56 n'est pas utile."> <span aria-hidden="true"> Non · <span class="bv-content-btn-count" aria-hidden="true">0</span> </span> </button> </div> <div class="bv-content-feedback-vote bv-content-feedback-vote-active"> <button type="button" class="bv-content-report-btn bv-focusable" aria-label="Marquer «&nbsp;Excellent&nbsp;» de Jo56 comme inapproprié."> Signalez un contenu inapproprié </button> </div> </div> </div> </div> <div class="bv-inline-form-container"></div> <div data-bv-v="secondaryContentList:15" class="bv-secondary-content-list"> <ol data-bv-v="secondaryContentItemCollection:16" class="bv-content-list bv-content-list-clientresponses" role="presentation"> </ol> </div> </div> </li> </ol> 例如,我尝试了以下方法: response.css('li.data-content-id').extract() 但它给了我一个空数组。 更新 在开发人员工具中查看页面的其他元素后,我正在查找的数据似乎在batch.json文档中给出: 数据是从此请求生成的: https://api.bazaarvoice.com/data/batch.json?passkey=iohrnzjadededr160osgfvimy&apiversion=5.5&displaycode=3232-fr_fr&resource.q0=products&filter.q0=id%3Aeq%3AP618001&stats.q0=questions%2Creviews&filteredstats.q0=questions %2Creviews&filter_questions.q0=contentlocale%3Aeq%3Afr_FR&filter_answers.q0=contentlocale%3Aeq%3Afr_FR&filter_reviews.q0=contentlocale%3Aeq%3Afr_FR&filter_reviewcomments.q0=contentlocale%3Aeq%3Afr_FR&resource.q1=questions&filter.q1=productid%3Aeq%3AP 618001&filter.q1=内容区域设置%3Aeq%3Afr_FR&sort.q1=lastapprovedanswersubmissiontime%3Adesc&stats.q1=questions&filteredstats.q1=questions&include.q1=authors%2Cproducts%2Canswers&filter_questions.q1=contentlocale%3Aeq%3Afr_FR&filter_answers.q1=contentlocale%3Aeq%3Afr_FR&limit.q1=10&off set.q1=0&limit_answers .q1=10&resource.q2=评论&filter.q2=is ratingsonly%3Aeq%3Afalse&filter.q2=productid%3Aeq%3AP618001&filter.q2=contentlocale%3Aeq%3Afr_FR&sort.q2=提交时间%3Adesc&stats.q2=评论&filteredstats.q2=评论&include.q2=作者%2Cproducts%2Ccomments&filter_reviews.q2=contentlocale%3Aeq%3Afr_FR&filter_reviewcomments.q2=contentlocale%3Aeq%3Afr_FR&filter_comments.q2=contentlocale%3Aeq%3Afr_FR&limit.q2=5&offset.q2=0&limit_comments.q2=3&callback=BV._internal.dataHandler0 由于我想自动化它,我想知道是否以及如何从它包含的信息或我可以从网站获得的信息中复制它。 您的代码使用类选择器。你的 html 告诉 data-content-id 是属性。不熟悉 scrapy 来判断它是否有属性选择的东西,但你可以使用 XPath 代替 response.xpath('//li[@data-content-id]') data-content-id 页面上某些其他类型的内容也可能有一些其他值,因此上面的 xpath 可能会获取不需要的部分。 以下 CSS 应该可以工作: response.css('[itemprop="review"]').get() 或者如果你真的想包含 data-content-id 那么我相信我们应该使用: response.css('[data-content-id*="Reviews-"]').get() 这将获取 data-content-id 属性包含 Reviews- 的所有元素。我们在这里使用通配符,因为评论后面的数字看起来像一个 ID,每个评论元素都会有所不同。 所需数据未在页面的html代码中呈现!! 它由单独的 Api 调用加载并由 javascript 呈现。 要查看原始 html 代码,您需要(在 Chrome 中)使用“查看源代码”选项 CTRL+U - 不检查 -> 元素。 其他信息 - > 抓取动态内容 (docs)

回答 3 投票 0

通过滚动抓取动态亚马逊页面

我正在尝试在亚马逊畅销书 100 中抓取特定类别的产品。例如 - https://www.amazon.com/Best-Sellers-Home-Kitchen/zgbs/home-garden/ref=zg_bs_nav_0 100 个产品...

回答 2 投票 0

如何从scrapy中的选择器中提取p标签内的内部文本

我使用CSS选择器来检索p标签,并且我试图从第一个p标签中提取文本。但它始终是包含 p 标签的 html 内容。 这是我的代码。 section_div = response.css('div[data-testid=&q...

回答 1 投票 0

如何在发送请求时使用随机用户代理?

我知道如何在scrapy中使用随机(假)用户代理。但在我运行 scrapy 之后。我在终端上只能看到一个随机用户代理。所以我猜当我运行 scrap 时,“settings.py”可能只运行一次...

回答 2 投票 0

如何从scrapy项目中获取字典?

我需要字典中的值。但 item 在其之上使用了一些抽象。如何从项目中获取字典中的字段? 我知道 scrapy 现在允许返回 dict 来代替 item 。但我已经...

回答 2 投票 0

使用 Scrapy Playwright 抓取网站时被阻止

我正在尝试抓取这个网站,但是当运行我的抓取工具时,该网站通过返回 405(或有时是 403)HTTP 代码来阻止我,您可以在我的蜘蛛日志中看到它: ... 2023-12-06 10:18:38 [

回答 1 投票 0

如何使用不同的参数触发相同的 Cloud Run 作业/服务?

我正在尝试使用云运行使 scrapy scraper 工作。主要思想是,云调度程序 cron 应该每 20 分钟触发一次网络爬虫并从不同站点获取数据。所有网站...

回答 3 投票 0

如何使用 chromium 引擎将 scrapy_splash 与 lua 结合使用?

您好, 我正在尝试为使用 javascript 的网站制作抓取机器人。我有大约 20 个来自该网站的网址,并且希望扩展到数百个,我需要经常抓取这些网址,所以我尝试了

回答 1 投票 0

M1 Mac 上的 Scrapy:内存错误:无法为 ffi.callback() 分配写入+执行内存

我是 scrapy 新手,最近开始在 M1 MacBook Air 上使用它。我遇到了一个问题。 例如,当我尝试做这样的事情时: scrapy shell bbc.com 它会返回给我:记忆...

回答 7 投票 0

Scrapy 不在 Jupyter Notebook 上保存 json 文件

我在 Jupyter Notebook 中创建了一个脚本,该脚本会废弃一个 url 并应将结果保存在 json 文件中,但它没有这样做,即使在日志中它说它会这样做。我正在使用 Google Drive 保存...

回答 1 投票 0

nslookup:isc_socket_bind:地址正在使用 - 无法解析 docker 容器中的 dns(phusion 图像)

我正在运行一个具有 2CPU、8GB RAM、450Mbps 带宽的 AWS 实例,以及一个保存 python 应用程序的 docker 容器。 当 Python 运行时,容器平均负载在白天几乎约为 6.0...

回答 1 投票 0

如何使用 scrapy-playwright 为每个请求使用新的上下文?

这是我的做法,但我不确定它是否为每个新请求创建和使用新上下文: 类 TestSpider(scrapy.Spider): 名称 = '测试' 开始网址 = [...] 碳纳米管 = 0 def start_re...

回答 1 投票 0

重定向到 PDF 文件时出现 Scrapy 错误:AttributeError:响应内容不是文本

我使用智能代理在 Zyte 上托管了一个 scrapy 蜘蛛。 我的蜘蛛相当简单,因为它从 URL 列表开始爬行。 parse 方法使用一个简单的链接提取器来提取

回答 1 投票 0

使用 Schedule.json 将 PHP 中的 CURL 转换为 SCRAPYD 不返回任何内容

我已经在我的服务器上设置了Scrapyd,一切似乎都工作正常。我可以使用 CURL 来获取我的蜘蛛列表,就像这样curl -u super:secret http://111.111.111.111:6800/listspiders.json?pro...

回答 1 投票 0

Scrapy/Celery 日志记录设置不起作用

我正在将 Scrapy 蜘蛛作为 Celery 任务运行。 问题是 Scrapy 不会登录到文件 scrapy.log。它会记录到 Celery 日志中。此外,我可以在 Celery 日志中看到 DEBUG 级别...

回答 5 投票 0

如何使用 scrapy 从 python 的输出中删除 u' ?

当我运行命令时,我得到如下所示的输出。如何删除你每次都收到的信息? [u'Massimo Eraldo Abate'、u'Valentina Abate'、u'Carlo Abbate'、u'Francesca Abbate'、u'Ines Abbate'、u'

回答 3 投票 0

使用 Xpath 从属性值获取元素名称

我正在尝试获取具有特定属性值的每个节点的元素/标签名称。 我有一个 xml: 这个 是 A&l...

回答 1 投票 0

我们是否可以选择同时“独立”运行多个蜘蛛?

这个问题已经被问过多次,但我没有看到任何可靠的答案。几年前,也有人问过这个问题:https://github.com/scrapy/scrapy/issues/3216。我目前运行着 300 多个蜘蛛

回答 1 投票 0

Scrapy 设置可以使用 custom_settings 工作,但不能在 settings.py 中工作

我一直在尝试编辑我的Spider中的一些设置,但它们似乎只有在我覆盖自定义Spider中的custom_settings字典时才起作用。 自定义设置 = { '下载延迟':1, '

回答 2 投票 0

Scrapy 将一个 CSV 中的所有数据导出到 AWS S3,而不是多个 CSV

我正在尝试使用 MultiCSVItemPipeline 将两个 csv 中的 Scrapy 抓取数据导出到 S3。它在我的计算机上运行良好,数据以两个单独的 csv 格式导出,但导出到 S 时...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.