Differences between two pages while scraping with Beautiful Soup
I'm beginning with Python and Beautiful Soup and I'm scraping Google PlayStore and applications metadata in a JSON file. Here is my code :
def createjson(app_link):
url = 'https://play.google.com/store/apps/details?id=' + app_link
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
bs = BeautifulSoup(response.text,"lxml")
result = [e.text for e in bs.find_all("div","class":"hAyfc")]
apptype = [e.text for e in bs.find_all("div","class":"hrTbp R8zArc")]
data =
data['appdata'] =
data['appdata'].append(
'name': html_soup.find(class_="AHFaub").text,
'updated': result[1][7:],
'apkSize': result[2][4:],
'offeredBy': result[9][10:],
'currentVersion': result[4][15:]
)
jsonfile = "allappsdata.json" #Get all the appS infos in one JSON
with open(jsonfile, 'a+') as outfile:
json.dump(data, outfile)
My 'result' variable looks for a string in a specific app page the problem is that Google is changing the order between two different pages. Sometimes result[1] is the application name, sometimes it's result[2]; Same problems for other metadata I need ('updated', 'apkSize', etc...) How can I deal with these changes. Is it possible to scrape in a different way? Thank you
python beautifulsoup google-play
add a comment |
I'm beginning with Python and Beautiful Soup and I'm scraping Google PlayStore and applications metadata in a JSON file. Here is my code :
def createjson(app_link):
url = 'https://play.google.com/store/apps/details?id=' + app_link
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
bs = BeautifulSoup(response.text,"lxml")
result = [e.text for e in bs.find_all("div","class":"hAyfc")]
apptype = [e.text for e in bs.find_all("div","class":"hrTbp R8zArc")]
data =
data['appdata'] =
data['appdata'].append(
'name': html_soup.find(class_="AHFaub").text,
'updated': result[1][7:],
'apkSize': result[2][4:],
'offeredBy': result[9][10:],
'currentVersion': result[4][15:]
)
jsonfile = "allappsdata.json" #Get all the appS infos in one JSON
with open(jsonfile, 'a+') as outfile:
json.dump(data, outfile)
My 'result' variable looks for a string in a specific app page the problem is that Google is changing the order between two different pages. Sometimes result[1] is the application name, sometimes it's result[2]; Same problems for other metadata I need ('updated', 'apkSize', etc...) How can I deal with these changes. Is it possible to scrape in a different way? Thank you
python beautifulsoup google-play
add a comment |
I'm beginning with Python and Beautiful Soup and I'm scraping Google PlayStore and applications metadata in a JSON file. Here is my code :
def createjson(app_link):
url = 'https://play.google.com/store/apps/details?id=' + app_link
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
bs = BeautifulSoup(response.text,"lxml")
result = [e.text for e in bs.find_all("div","class":"hAyfc")]
apptype = [e.text for e in bs.find_all("div","class":"hrTbp R8zArc")]
data =
data['appdata'] =
data['appdata'].append(
'name': html_soup.find(class_="AHFaub").text,
'updated': result[1][7:],
'apkSize': result[2][4:],
'offeredBy': result[9][10:],
'currentVersion': result[4][15:]
)
jsonfile = "allappsdata.json" #Get all the appS infos in one JSON
with open(jsonfile, 'a+') as outfile:
json.dump(data, outfile)
My 'result' variable looks for a string in a specific app page the problem is that Google is changing the order between two different pages. Sometimes result[1] is the application name, sometimes it's result[2]; Same problems for other metadata I need ('updated', 'apkSize', etc...) How can I deal with these changes. Is it possible to scrape in a different way? Thank you
python beautifulsoup google-play
I'm beginning with Python and Beautiful Soup and I'm scraping Google PlayStore and applications metadata in a JSON file. Here is my code :
def createjson(app_link):
url = 'https://play.google.com/store/apps/details?id=' + app_link
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
bs = BeautifulSoup(response.text,"lxml")
result = [e.text for e in bs.find_all("div","class":"hAyfc")]
apptype = [e.text for e in bs.find_all("div","class":"hrTbp R8zArc")]
data =
data['appdata'] =
data['appdata'].append(
'name': html_soup.find(class_="AHFaub").text,
'updated': result[1][7:],
'apkSize': result[2][4:],
'offeredBy': result[9][10:],
'currentVersion': result[4][15:]
)
jsonfile = "allappsdata.json" #Get all the appS infos in one JSON
with open(jsonfile, 'a+') as outfile:
json.dump(data, outfile)
My 'result' variable looks for a string in a specific app page the problem is that Google is changing the order between two different pages. Sometimes result[1] is the application name, sometimes it's result[2]; Same problems for other metadata I need ('updated', 'apkSize', etc...) How can I deal with these changes. Is it possible to scrape in a different way? Thank you
python beautifulsoup google-play
python beautifulsoup google-play
asked Nov 13 '18 at 21:21
userHGuserHG
1319
1319
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
the problem is python loop is not ordered, save it as dict not list. Change your result = [e....]
with
result =
details = bs.find_all("div","class":"hAyfc")
for item in details:
label = item.findChild('div', 'class' : 'BgcNfc')
value = item.findChild('span', 'class' : 'htlgb')
result[label.text] = value.text
also data['appdata']...
with
data['appdata'].append({
'name': html_soup.find(class_="AHFaub").text,
'updated': result['Updated'],
'apkSize': result['Size'],
'offeredBy': result['Offered By'],
'currentVersion': result['Current Version']
Great answer, thank you !
– userHG
Nov 14 '18 at 20:37
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%2f53289664%2fdifferences-between-two-pages-while-scraping-with-beautiful-soup%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
the problem is python loop is not ordered, save it as dict not list. Change your result = [e....]
with
result =
details = bs.find_all("div","class":"hAyfc")
for item in details:
label = item.findChild('div', 'class' : 'BgcNfc')
value = item.findChild('span', 'class' : 'htlgb')
result[label.text] = value.text
also data['appdata']...
with
data['appdata'].append({
'name': html_soup.find(class_="AHFaub").text,
'updated': result['Updated'],
'apkSize': result['Size'],
'offeredBy': result['Offered By'],
'currentVersion': result['Current Version']
Great answer, thank you !
– userHG
Nov 14 '18 at 20:37
add a comment |
the problem is python loop is not ordered, save it as dict not list. Change your result = [e....]
with
result =
details = bs.find_all("div","class":"hAyfc")
for item in details:
label = item.findChild('div', 'class' : 'BgcNfc')
value = item.findChild('span', 'class' : 'htlgb')
result[label.text] = value.text
also data['appdata']...
with
data['appdata'].append({
'name': html_soup.find(class_="AHFaub").text,
'updated': result['Updated'],
'apkSize': result['Size'],
'offeredBy': result['Offered By'],
'currentVersion': result['Current Version']
Great answer, thank you !
– userHG
Nov 14 '18 at 20:37
add a comment |
the problem is python loop is not ordered, save it as dict not list. Change your result = [e....]
with
result =
details = bs.find_all("div","class":"hAyfc")
for item in details:
label = item.findChild('div', 'class' : 'BgcNfc')
value = item.findChild('span', 'class' : 'htlgb')
result[label.text] = value.text
also data['appdata']...
with
data['appdata'].append({
'name': html_soup.find(class_="AHFaub").text,
'updated': result['Updated'],
'apkSize': result['Size'],
'offeredBy': result['Offered By'],
'currentVersion': result['Current Version']
the problem is python loop is not ordered, save it as dict not list. Change your result = [e....]
with
result =
details = bs.find_all("div","class":"hAyfc")
for item in details:
label = item.findChild('div', 'class' : 'BgcNfc')
value = item.findChild('span', 'class' : 'htlgb')
result[label.text] = value.text
also data['appdata']...
with
data['appdata'].append({
'name': html_soup.find(class_="AHFaub").text,
'updated': result['Updated'],
'apkSize': result['Size'],
'offeredBy': result['Offered By'],
'currentVersion': result['Current Version']
answered Nov 14 '18 at 10:31
ewwinkewwink
11.9k22239
11.9k22239
Great answer, thank you !
– userHG
Nov 14 '18 at 20:37
add a comment |
Great answer, thank you !
– userHG
Nov 14 '18 at 20:37
Great answer, thank you !
– userHG
Nov 14 '18 at 20:37
Great answer, thank you !
– userHG
Nov 14 '18 at 20:37
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%2f53289664%2fdifferences-between-two-pages-while-scraping-with-beautiful-soup%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