Reputation: 23
Hello im trying to get hashtags list from caption.. only will scraping data if only the data start with '#'
hashtags = driver.find_elements(By.CSS_SELECTOR, "li > div > div > div._a9zr > div._a9zs > span > a")
for tag in hashtags:
print(tag.text)
it still mixed with @ data
@flutter_coding_
#softwareengineer
#iosdeveloper
#webdeveloper
#flutterdeveloper
#frontenddeveloper
#appdeveloper
#programming
#softwareengineer
#coding
#code
#100daysofcode
#javascript
#reactjs
#developer
#developerlife
#programminghumor
#coderlife
#python
#php
#desksetup
#appdevelopment
#uidesign
#frontend
#backenddeveloper
#codinggirl
#flutter
Upvotes: 0
Views: 55
Reputation: 16187
You can use startswith()
method to sort and to get the data items those contain only #
for tag in hashtags:
if tag.startswith('#'):
print(tag.text)
Try:
At first,you have to invoke .text
method then startswith(
)` method with if condition
for tag in hashtags:
tag=tag.text
if tag.startswith('#'):
print(tag)
Upvotes: 2
Reputation: 5223
You cal filter the list with a comprehension:
hashtags = ["@flutter_coding_", "#softwareengineer", "#iosdeveloper"]
hashtags = [i for i in hashtags if i[0]=="#"]
print(hashtags )
Output:
['#softwareengineer', '#iosdeveloper']
Upvotes: 1