

Python. Scrapy Xpath returns an empty array
source link: https://www.codesd.com/item/python-scrapy-xpath-returns-an-empty-array.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python. Scrapy Xpath returns an empty array
I am using scrapy
to scrape information from a website in python
and I am only getting used to using Xpaths to find information.
I want to return a list of all the average ratings from albums of this artist from this page. https://rateyourmusic.com/artist/kanye_west
To find the node for the albums I used //div[@id="disco_type_s"]
and I tried searching children for divs with the attribute disco_avg_rating
using div[@class="disco_avg_rating"]/text()
Here is my function
def parse_dir_contents(self, response):
item = rateyourmusicalbums() *ignore this
for i in response.xpath('//div[@id="disco_type_s"]'):
item['average rating']=i.xpath('div[@class="disco_avg_rating"]/text()').extract()
yield item
Everything I try to get this list causes a problems. Usually it's more straight but this time I have to differentiate between albums and singles etc. so I am having troubles.
Appreciate your help, I am fairly new to web scraping.
response.xpath('//div[@id="disco_type_s"]')
finds only one tag (this is what mostly happens when using id
to match the xpath, they are unique). to get a list of selectors you should use something like:
response.xpath('//div[@id="disco_type_s"]/div[@class="disco_release"]')
which will match multiple tags, so you can iterate on those.
then get the average rating
with './div[@class="disco_avg_rating"]/text()'
Recommend
-
6
Array.slice (1, 1) gives me an empty array advertisements Why does array.slice(1, 1)/array.slice(2, 2) returns an empty array, wh...
-
7
extract only one part of xpath scrapy advertisements I want to extract from a web page information with xpath, but I'm getting the wrong infor...
-
11
While working with arrays in javascript, often there is a requirement to check if an array is empty or not. This article will describe how to check if an array is empty or exists in javascript. Table of Contents:-...
-
7
目录 1 XPath概述
-
4
# yyds干货盘点 # Python解析库lxml与xpath用法总结 原创 本文主要围绕以xpath和lxml库进行展开:一...
-
8
In this article we will learn how to create an empty NumPy array in Python. Table Of Contents What is an empty Numpy array? The size of an empty array is zero, and it does...
-
10
Python program to Initialize Empty Array of Given LengthSkip to content
-
5
Gigi Sohn returns to Congress for a third try at securing empty FCC chair / Gigi Sohn’s stalled nomination has blocked the FCC from reinstating net neutrality, among other White House priorities.
-
14
This tutorial will discuss about unique ways to check if numpy array contains only empty strings. Table Of Contents Method 1: using numpy.char.str_len() The numpy
-
8
XPath(XML Path Language)是一种在XML文档中查找信息的语言。它同样适用于HTML,因为HTML是XML的子集。XPath提供了非常强大的语法来定位HTML文档中的元素。在这篇技术博客中,我们将探讨如何使用Python的lxml库和XPath来提取HTML页面的信息。
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK