Reputation: 21
Hello hope you're all doing well I wrote the following program to extract the data from it's source but it gives me the last value and I don't know why
users_list = soup.find_all("li", class_= "ContentGrid-gridItem-2Ad e2e-ContentGriditem")
for user in users_list:
name = user.find("span", class_ = "e2e-UserSummary-displayName")
profile_link = user.find('a', class_='UserSummary-ownerLink-1cJ')
the variable profile_link gives me this output
<a class="UserSummary-ownerLink-1cJ"
href="https://www.behance.net/baianat?tracking_source=search_users"
target="_blank"></a>
i want to make it return only the link
another thing also I built other variables to return values but it keep returning the same values because it's having the same class and they all in h4 here's the code and it's returning the value of the first object which is appreciations 189.9k
appreciations = users.find("h4", class_= "UserSummaryStats-statAmount-13R").text
followers = users.find("h4", class_= "UserSummaryStats-statAmount-13R").text
project_views = users.find("h4", class_= "UserSummaryStats-statAmount-13R").text
Upvotes: 2
Views: 328
Reputation: 2692
To extract only href attribute of the tag you can use tag['<attr>']
. For example:
profile_link = user.find('a', class_='UserSummary-ownerLink-1cJ')['href']
For the second case, just use .find_all(<tag_name>, <params>)
method which returns all the tags with defined parameters as a list:
user_data = users.find_all("h4", class_= "UserSummaryStats-statAmount-13R")
for entry in user_data:
# do something with each entry
Upvotes: 1