Siddharth St Siddharth St - 8 days ago 6
Python Question

Python how do I convert this into an array

My Print statement in python Produces an output like this -

3858
47706
3859


How do I convert into an array which looks like this - ["3858", "47706", "3859"]

I tried numpy - asarray. It didn't work. Any suggestions? Thanks in advance

The code looks like this -

for e in driver.find_elements_by_css_selector("[data-listing-id]"):
A=(e.get_attribute("data-listing-id"))
print(A)


The Print statement produces the above mentioned output.

I Attempted Numpy -

myarray = np.asarray(A)
print(myarray)


No change in the output.

Answer

You have for-loop so you get one element and print one element.

You have to add elements to one array and after for-loop print all.

ie. more or less

results = []

for e in driver.find_elements_by_css_selector("[data-listing-id]"):
    A = e.get_attribute("data-listing-id")
    results.append(A)

print(results)
Comments