Question

So I'm new to web scraping and I've been stuck on this problem for awhile now.

I'm using Python w/ Regex to try and get a certain value of a class and while I do get the information I want, I get it in an array followed by a bunch of other junk I don't want. How do I get regex to only give me the first of the array?

The line of code looks like this:

'<td class="item_dropped">(.+?)</td>'

And to visualize the above statement the data that comes out looks like this:

['1,453,343,231 ABC', '24,131,411 TPP', '<a href="/item/13445/">Foo</a>', '<a href="/item/3453/">Bar</a>']

and I am trying to only grab "1,453,343,231 ABC" out of that. Can anyone please help me?

Was it helpful?

Solution

Well if your list variable is called result, you can do:

>>> print result[0]
1,453,343,231 ABC

The list_name[index] syntax fetches the element of the list at the number index (indexing starts at 0). Therefore, the index of 0 will fetch the 1st element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top