【发布时间】:2020-10-22 09:42:44
【问题描述】:
我将这个脚本与 Scrapy 一起使用:
import scrapy
class PageSpider(scrapy.Spider):
name = "page"
start_urls = ['http://blog.theodo.com/']
def parse(self, response):
for article_url in response.css('.Link-sc-19p3alm-0 fnuPWK a ::attr("href")').extract():
yield response.follow(article_url, callback=self.parse_article)
def parse_article(self, response):
content = response.xpath(".//div[@class='entry-content']/descendant::text()").extract()
yield {'article': ''.join(content)}
我正在学习教程,但我猜有些部分需要更改。
我已经改变了:
response.css('.Link-sc-19p3alm-0 fnuPWK a ::attr("href")').extract():
我想这就是我获取文章链接所需要的->
但我坚持使用 xpath。文章的所有内容都包含在一个 div 中,但没有 entry-content 了:
我想知道我是否在 response.css 中放入了正确的东西,以及我需要在 xpath 中编写的路径并理解其背后的逻辑。
谢谢你,我希望我的帖子很清楚:)
【问题讨论】:
标签: python-3.x web-scraping scrapy