Extract data using Beautiful Soup and Requests
I am trying to scrape data from Stackoverflow using Beautiful soup
and requests
package in Python. I have been able to extract most of the details, however when I try to extract the reputation scores of an user I am only able to pull data for reputation score
and Gold
, but not able to extract data for Silver
and Bronze
counts.
Given below is the code I am using to extract:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop').text
soup = BeautifulSoup(source,'lxml')
article = soup.find('div', class_='inner-content clearfix')
user_reputation_score = article.find('span', class_='reputation-score').text
print(user_reputation_score)
Code for Gold badge:
gold_badge = article.find('div', class_='-flair').find('span', class_='badgecount').text
print(gold_badge)
Wondering how to extend the above to extract data for Silver and Bronze batches.
Use the below link to test:
https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop
Please note I am doing this for pure educational purpose. Thanks.
python beautifulsoup python-requests
add a comment |
I am trying to scrape data from Stackoverflow using Beautiful soup
and requests
package in Python. I have been able to extract most of the details, however when I try to extract the reputation scores of an user I am only able to pull data for reputation score
and Gold
, but not able to extract data for Silver
and Bronze
counts.
Given below is the code I am using to extract:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop').text
soup = BeautifulSoup(source,'lxml')
article = soup.find('div', class_='inner-content clearfix')
user_reputation_score = article.find('span', class_='reputation-score').text
print(user_reputation_score)
Code for Gold badge:
gold_badge = article.find('div', class_='-flair').find('span', class_='badgecount').text
print(gold_badge)
Wondering how to extend the above to extract data for Silver and Bronze batches.
Use the below link to test:
https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop
Please note I am doing this for pure educational purpose. Thanks.
python beautifulsoup python-requests
add a comment |
I am trying to scrape data from Stackoverflow using Beautiful soup
and requests
package in Python. I have been able to extract most of the details, however when I try to extract the reputation scores of an user I am only able to pull data for reputation score
and Gold
, but not able to extract data for Silver
and Bronze
counts.
Given below is the code I am using to extract:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop').text
soup = BeautifulSoup(source,'lxml')
article = soup.find('div', class_='inner-content clearfix')
user_reputation_score = article.find('span', class_='reputation-score').text
print(user_reputation_score)
Code for Gold badge:
gold_badge = article.find('div', class_='-flair').find('span', class_='badgecount').text
print(gold_badge)
Wondering how to extend the above to extract data for Silver and Bronze batches.
Use the below link to test:
https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop
Please note I am doing this for pure educational purpose. Thanks.
python beautifulsoup python-requests
I am trying to scrape data from Stackoverflow using Beautiful soup
and requests
package in Python. I have been able to extract most of the details, however when I try to extract the reputation scores of an user I am only able to pull data for reputation score
and Gold
, but not able to extract data for Silver
and Bronze
counts.
Given below is the code I am using to extract:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop').text
soup = BeautifulSoup(source,'lxml')
article = soup.find('div', class_='inner-content clearfix')
user_reputation_score = article.find('span', class_='reputation-score').text
print(user_reputation_score)
Code for Gold badge:
gold_badge = article.find('div', class_='-flair').find('span', class_='badgecount').text
print(gold_badge)
Wondering how to extend the above to extract data for Silver and Bronze batches.
Use the below link to test:
https://stackoverflow.com/questions/53968946/how-can-i-limit-function-slot-play-just-for-5-turn-with-do-while-loop
Please note I am doing this for pure educational purpose. Thanks.
python beautifulsoup python-requests
python beautifulsoup python-requests
edited Dec 29 '18 at 23:20
ewwink
11.6k22238
11.6k22238
asked Dec 29 '18 at 16:15
dark horsedark horse
14810
14810
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
find()
return first element, to get multiple element use find_all()
badge = article.find('div', class_='-flair').find_all('span', class_='badgecount')
gold_badge = badge[0].text
silver_badge = badge[1].text
bronze_badge = badge[2].text
print(gold_badge, silver_badge, bronze_badge) # 2 7 26
thanks that helped..
– dark horse
Jan 2 at 11:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971195%2fextract-data-using-beautiful-soup-and-requests%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
find()
return first element, to get multiple element use find_all()
badge = article.find('div', class_='-flair').find_all('span', class_='badgecount')
gold_badge = badge[0].text
silver_badge = badge[1].text
bronze_badge = badge[2].text
print(gold_badge, silver_badge, bronze_badge) # 2 7 26
thanks that helped..
– dark horse
Jan 2 at 11:10
add a comment |
find()
return first element, to get multiple element use find_all()
badge = article.find('div', class_='-flair').find_all('span', class_='badgecount')
gold_badge = badge[0].text
silver_badge = badge[1].text
bronze_badge = badge[2].text
print(gold_badge, silver_badge, bronze_badge) # 2 7 26
thanks that helped..
– dark horse
Jan 2 at 11:10
add a comment |
find()
return first element, to get multiple element use find_all()
badge = article.find('div', class_='-flair').find_all('span', class_='badgecount')
gold_badge = badge[0].text
silver_badge = badge[1].text
bronze_badge = badge[2].text
print(gold_badge, silver_badge, bronze_badge) # 2 7 26
find()
return first element, to get multiple element use find_all()
badge = article.find('div', class_='-flair').find_all('span', class_='badgecount')
gold_badge = badge[0].text
silver_badge = badge[1].text
bronze_badge = badge[2].text
print(gold_badge, silver_badge, bronze_badge) # 2 7 26
answered Dec 29 '18 at 17:31
ewwinkewwink
11.6k22238
11.6k22238
thanks that helped..
– dark horse
Jan 2 at 11:10
add a comment |
thanks that helped..
– dark horse
Jan 2 at 11:10
thanks that helped..
– dark horse
Jan 2 at 11:10
thanks that helped..
– dark horse
Jan 2 at 11:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971195%2fextract-data-using-beautiful-soup-and-requests%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown