BeautifulSoup - Find elements Directly below and above heading with specific string
How can I scrape the following structure to only get h3,h4 class above h5 string ="Prem League" and div class="fixres_item" directly below h5 string "Prem League".
I would want the text from h3, h4 and inside the div I need the text from a span , inside a span
So when h5 class string is Prem League I want the h4 and h3 directly above, and also I need to geyt various elements our of the fixres_item directly below h5 class string = Prem League
<div class="fixres__body" data-url="" data-view="fixture-update" data-controller="fixture-update" data-fn="live-refresh" data-sport="football" data-lite="true" id="widgetLite-6">
<h3 class="fixres__header1">November 2018</h3>
<h4 class="fixres__header2">Saturday 24th November</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
<h4 class="fixres__header2">Wednesday 28th November</h4>
<h5 class="fixres__header3">UEFA Champ League</h5>
<div class="fixres__item">stuff in here</div>
<h3 class="fixres__header1">December 2018</h3>
<h4 class="fixres__header2">Sunday 2nd December</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
This is the code I have so far, but this includes data from divs below h5 string "EUFA Champ League" - which I do not want. I only want data from the divs that are below h5 heading "Prem League". For example I do not want PSG in the output because it comes from the div below h5 heading "EUFA Champ League"
My Code -
def squad_fixtures():
team_table = ['https://someurl.com/liverpool-fixtures']
for i in team_table:
# team_fixture_urls = [i.replace('-squad', '-fixtures') for i in team_table]
squad_r = requests.get(i)
premier_squad_soup = BeautifulSoup(squad_r.text, 'html.parser')
# print(premier_squad_soup)
premier_fix_body = premier_squad_soup.find('div', {'class': 'fixres__body'})
# print(premier_fix_body)
premier_fix_divs = premier_fix_body.find_all('div', {'class': 'fixres__item'})
for i in premier_fix_divs:
team_home = i.find_all('span', {'class': 'matches__item-col matches__participant matches__participant--side1'})
for i in team_home:
team_home_names = i.find('span', {'class': 'swap-text--bp30'})['title']
team_home_namesall.append(team_home_names)
print(team_home_namesall)
The output
['Watford', 'PSG', 'Liverpool', 'Burnley', "B'mouth", 'Liverpool', 'Liverpool', 'Wolves', 'Liverpool', 'Liverpool', 'Man City', 'Brighton', 'Liverpool', 'Liverpool', 'West Ham', 'Liverpool', 'Man Utd', 'Liverpool', 'Everton', 'Liverpool', 'Fulham', 'Liverpool', "So'ton", 'Liverpool', 'Cardiff', 'Liverpool', 'Newcastle', 'Liverpool']
python python-3.x beautifulsoup
add a comment |
How can I scrape the following structure to only get h3,h4 class above h5 string ="Prem League" and div class="fixres_item" directly below h5 string "Prem League".
I would want the text from h3, h4 and inside the div I need the text from a span , inside a span
So when h5 class string is Prem League I want the h4 and h3 directly above, and also I need to geyt various elements our of the fixres_item directly below h5 class string = Prem League
<div class="fixres__body" data-url="" data-view="fixture-update" data-controller="fixture-update" data-fn="live-refresh" data-sport="football" data-lite="true" id="widgetLite-6">
<h3 class="fixres__header1">November 2018</h3>
<h4 class="fixres__header2">Saturday 24th November</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
<h4 class="fixres__header2">Wednesday 28th November</h4>
<h5 class="fixres__header3">UEFA Champ League</h5>
<div class="fixres__item">stuff in here</div>
<h3 class="fixres__header1">December 2018</h3>
<h4 class="fixres__header2">Sunday 2nd December</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
This is the code I have so far, but this includes data from divs below h5 string "EUFA Champ League" - which I do not want. I only want data from the divs that are below h5 heading "Prem League". For example I do not want PSG in the output because it comes from the div below h5 heading "EUFA Champ League"
My Code -
def squad_fixtures():
team_table = ['https://someurl.com/liverpool-fixtures']
for i in team_table:
# team_fixture_urls = [i.replace('-squad', '-fixtures') for i in team_table]
squad_r = requests.get(i)
premier_squad_soup = BeautifulSoup(squad_r.text, 'html.parser')
# print(premier_squad_soup)
premier_fix_body = premier_squad_soup.find('div', {'class': 'fixres__body'})
# print(premier_fix_body)
premier_fix_divs = premier_fix_body.find_all('div', {'class': 'fixres__item'})
for i in premier_fix_divs:
team_home = i.find_all('span', {'class': 'matches__item-col matches__participant matches__participant--side1'})
for i in team_home:
team_home_names = i.find('span', {'class': 'swap-text--bp30'})['title']
team_home_namesall.append(team_home_names)
print(team_home_namesall)
The output
['Watford', 'PSG', 'Liverpool', 'Burnley', "B'mouth", 'Liverpool', 'Liverpool', 'Wolves', 'Liverpool', 'Liverpool', 'Man City', 'Brighton', 'Liverpool', 'Liverpool', 'West Ham', 'Liverpool', 'Man Utd', 'Liverpool', 'Everton', 'Liverpool', 'Fulham', 'Liverpool', "So'ton", 'Liverpool', 'Cardiff', 'Liverpool', 'Newcastle', 'Liverpool']
python python-3.x beautifulsoup
show your python code
– ewwink
Nov 22 '18 at 21:34
@ewwink - updated and added the code
– anfield
Nov 22 '18 at 22:28
add a comment |
How can I scrape the following structure to only get h3,h4 class above h5 string ="Prem League" and div class="fixres_item" directly below h5 string "Prem League".
I would want the text from h3, h4 and inside the div I need the text from a span , inside a span
So when h5 class string is Prem League I want the h4 and h3 directly above, and also I need to geyt various elements our of the fixres_item directly below h5 class string = Prem League
<div class="fixres__body" data-url="" data-view="fixture-update" data-controller="fixture-update" data-fn="live-refresh" data-sport="football" data-lite="true" id="widgetLite-6">
<h3 class="fixres__header1">November 2018</h3>
<h4 class="fixres__header2">Saturday 24th November</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
<h4 class="fixres__header2">Wednesday 28th November</h4>
<h5 class="fixres__header3">UEFA Champ League</h5>
<div class="fixres__item">stuff in here</div>
<h3 class="fixres__header1">December 2018</h3>
<h4 class="fixres__header2">Sunday 2nd December</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
This is the code I have so far, but this includes data from divs below h5 string "EUFA Champ League" - which I do not want. I only want data from the divs that are below h5 heading "Prem League". For example I do not want PSG in the output because it comes from the div below h5 heading "EUFA Champ League"
My Code -
def squad_fixtures():
team_table = ['https://someurl.com/liverpool-fixtures']
for i in team_table:
# team_fixture_urls = [i.replace('-squad', '-fixtures') for i in team_table]
squad_r = requests.get(i)
premier_squad_soup = BeautifulSoup(squad_r.text, 'html.parser')
# print(premier_squad_soup)
premier_fix_body = premier_squad_soup.find('div', {'class': 'fixres__body'})
# print(premier_fix_body)
premier_fix_divs = premier_fix_body.find_all('div', {'class': 'fixres__item'})
for i in premier_fix_divs:
team_home = i.find_all('span', {'class': 'matches__item-col matches__participant matches__participant--side1'})
for i in team_home:
team_home_names = i.find('span', {'class': 'swap-text--bp30'})['title']
team_home_namesall.append(team_home_names)
print(team_home_namesall)
The output
['Watford', 'PSG', 'Liverpool', 'Burnley', "B'mouth", 'Liverpool', 'Liverpool', 'Wolves', 'Liverpool', 'Liverpool', 'Man City', 'Brighton', 'Liverpool', 'Liverpool', 'West Ham', 'Liverpool', 'Man Utd', 'Liverpool', 'Everton', 'Liverpool', 'Fulham', 'Liverpool', "So'ton", 'Liverpool', 'Cardiff', 'Liverpool', 'Newcastle', 'Liverpool']
python python-3.x beautifulsoup
How can I scrape the following structure to only get h3,h4 class above h5 string ="Prem League" and div class="fixres_item" directly below h5 string "Prem League".
I would want the text from h3, h4 and inside the div I need the text from a span , inside a span
So when h5 class string is Prem League I want the h4 and h3 directly above, and also I need to geyt various elements our of the fixres_item directly below h5 class string = Prem League
<div class="fixres__body" data-url="" data-view="fixture-update" data-controller="fixture-update" data-fn="live-refresh" data-sport="football" data-lite="true" id="widgetLite-6">
<h3 class="fixres__header1">November 2018</h3>
<h4 class="fixres__header2">Saturday 24th November</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
<h4 class="fixres__header2">Wednesday 28th November</h4>
<h5 class="fixres__header3">UEFA Champ League</h5>
<div class="fixres__item">stuff in here</div>
<h3 class="fixres__header1">December 2018</h3>
<h4 class="fixres__header2">Sunday 2nd December</h4>
<h5 class="fixres__header3">Prem League</h5>
<div class="fixres__item">stuff in here</div>
This is the code I have so far, but this includes data from divs below h5 string "EUFA Champ League" - which I do not want. I only want data from the divs that are below h5 heading "Prem League". For example I do not want PSG in the output because it comes from the div below h5 heading "EUFA Champ League"
My Code -
def squad_fixtures():
team_table = ['https://someurl.com/liverpool-fixtures']
for i in team_table:
# team_fixture_urls = [i.replace('-squad', '-fixtures') for i in team_table]
squad_r = requests.get(i)
premier_squad_soup = BeautifulSoup(squad_r.text, 'html.parser')
# print(premier_squad_soup)
premier_fix_body = premier_squad_soup.find('div', {'class': 'fixres__body'})
# print(premier_fix_body)
premier_fix_divs = premier_fix_body.find_all('div', {'class': 'fixres__item'})
for i in premier_fix_divs:
team_home = i.find_all('span', {'class': 'matches__item-col matches__participant matches__participant--side1'})
for i in team_home:
team_home_names = i.find('span', {'class': 'swap-text--bp30'})['title']
team_home_namesall.append(team_home_names)
print(team_home_namesall)
The output
['Watford', 'PSG', 'Liverpool', 'Burnley', "B'mouth", 'Liverpool', 'Liverpool', 'Wolves', 'Liverpool', 'Liverpool', 'Man City', 'Brighton', 'Liverpool', 'Liverpool', 'West Ham', 'Liverpool', 'Man Utd', 'Liverpool', 'Everton', 'Liverpool', 'Fulham', 'Liverpool', "So'ton", 'Liverpool', 'Cardiff', 'Liverpool', 'Newcastle', 'Liverpool']
python python-3.x beautifulsoup
python python-3.x beautifulsoup
edited Nov 22 '18 at 22:39
anfield
asked Nov 22 '18 at 20:23
anfieldanfield
688
688
show your python code
– ewwink
Nov 22 '18 at 21:34
@ewwink - updated and added the code
– anfield
Nov 22 '18 at 22:28
add a comment |
show your python code
– ewwink
Nov 22 '18 at 21:34
@ewwink - updated and added the code
– anfield
Nov 22 '18 at 22:28
show your python code
– ewwink
Nov 22 '18 at 21:34
show your python code
– ewwink
Nov 22 '18 at 21:34
@ewwink - updated and added the code
– anfield
Nov 22 '18 at 22:28
@ewwink - updated and added the code
– anfield
Nov 22 '18 at 22:28
add a comment |
1 Answer
1
active
oldest
votes
It seems like your challenge is restricting the scraping to just the Premier League
<h5>
and its associated content.
Note: Your question states the
string
of theh5
should bePrem League
, but it in fact appears to bePremier League
when I look at the response.
This HTML appears to be pretty flat and undifferentiated in structure, so it looks like the best thing is to walk through the siblings previous and next from the h5, which is itself fairly easy to locate:
import re
from bs4 import BeautifulSoup, Tag
import requests
prem_league_regex = re.compile(r"Premier League")
def squad_fixtures():
team_table = ['https://www.skysports.com/liverpool-fixtures']
for i in team_table:
squad_r = requests.get(i)
soup = BeautifulSoup(squad_r.text, 'html.parser')
body = soup.find('div', {'class': 'fixres__body'})
h5s = body.find_all('h5', {'class': 'fixres__header3'}, text=prem_league_regex)
for h5 in h5s:
prev_tag = find_previous(h5)
if prev_tag.name == 'h4':
print(prev_tag.text)
prev_tag = find_previous(prev_tag)
if prev_tag.name == 'h3':
print(prev_tag.text)
fixres_item_div = find_next(h5)
"""
get the things you need from fixres__item now that you have it...
"""
def find_previous(tag):
prev_tag = tag.previous_sibling
while(not isinstance(prev_tag, Tag)):
prev_tag = prev_tag.previous_sibling
return prev_tag
def find_next(tag):
next_tag = tag.next_sibling
while(not isinstance(next_tag, Tag)):
next_tag = next_tag.next_sibling
return next_tag
Yes the h5 string is Premier League. I will give that a try thanks
– anfield
Nov 22 '18 at 23:03
fixres_item_div seems to only pull one div, any idea why that would be?
– anfield
Nov 23 '18 at 3:08
1
Since you have more than one h5 tag you're trying to find (I misunderstood that), usefind_all
instead offind
, and iterate on the results. I've updated my answer.
– Matt Morgan
Nov 23 '18 at 12:29
That works well, much appreciated.
– anfield
Nov 23 '18 at 14:26
1
done, thanks...
– anfield
Nov 23 '18 at 17:07
|
show 1 more 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%2f53437616%2fbeautifulsoup-find-elements-directly-below-and-above-heading-with-specific-str%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
It seems like your challenge is restricting the scraping to just the Premier League
<h5>
and its associated content.
Note: Your question states the
string
of theh5
should bePrem League
, but it in fact appears to bePremier League
when I look at the response.
This HTML appears to be pretty flat and undifferentiated in structure, so it looks like the best thing is to walk through the siblings previous and next from the h5, which is itself fairly easy to locate:
import re
from bs4 import BeautifulSoup, Tag
import requests
prem_league_regex = re.compile(r"Premier League")
def squad_fixtures():
team_table = ['https://www.skysports.com/liverpool-fixtures']
for i in team_table:
squad_r = requests.get(i)
soup = BeautifulSoup(squad_r.text, 'html.parser')
body = soup.find('div', {'class': 'fixres__body'})
h5s = body.find_all('h5', {'class': 'fixres__header3'}, text=prem_league_regex)
for h5 in h5s:
prev_tag = find_previous(h5)
if prev_tag.name == 'h4':
print(prev_tag.text)
prev_tag = find_previous(prev_tag)
if prev_tag.name == 'h3':
print(prev_tag.text)
fixres_item_div = find_next(h5)
"""
get the things you need from fixres__item now that you have it...
"""
def find_previous(tag):
prev_tag = tag.previous_sibling
while(not isinstance(prev_tag, Tag)):
prev_tag = prev_tag.previous_sibling
return prev_tag
def find_next(tag):
next_tag = tag.next_sibling
while(not isinstance(next_tag, Tag)):
next_tag = next_tag.next_sibling
return next_tag
Yes the h5 string is Premier League. I will give that a try thanks
– anfield
Nov 22 '18 at 23:03
fixres_item_div seems to only pull one div, any idea why that would be?
– anfield
Nov 23 '18 at 3:08
1
Since you have more than one h5 tag you're trying to find (I misunderstood that), usefind_all
instead offind
, and iterate on the results. I've updated my answer.
– Matt Morgan
Nov 23 '18 at 12:29
That works well, much appreciated.
– anfield
Nov 23 '18 at 14:26
1
done, thanks...
– anfield
Nov 23 '18 at 17:07
|
show 1 more comment
It seems like your challenge is restricting the scraping to just the Premier League
<h5>
and its associated content.
Note: Your question states the
string
of theh5
should bePrem League
, but it in fact appears to bePremier League
when I look at the response.
This HTML appears to be pretty flat and undifferentiated in structure, so it looks like the best thing is to walk through the siblings previous and next from the h5, which is itself fairly easy to locate:
import re
from bs4 import BeautifulSoup, Tag
import requests
prem_league_regex = re.compile(r"Premier League")
def squad_fixtures():
team_table = ['https://www.skysports.com/liverpool-fixtures']
for i in team_table:
squad_r = requests.get(i)
soup = BeautifulSoup(squad_r.text, 'html.parser')
body = soup.find('div', {'class': 'fixres__body'})
h5s = body.find_all('h5', {'class': 'fixres__header3'}, text=prem_league_regex)
for h5 in h5s:
prev_tag = find_previous(h5)
if prev_tag.name == 'h4':
print(prev_tag.text)
prev_tag = find_previous(prev_tag)
if prev_tag.name == 'h3':
print(prev_tag.text)
fixres_item_div = find_next(h5)
"""
get the things you need from fixres__item now that you have it...
"""
def find_previous(tag):
prev_tag = tag.previous_sibling
while(not isinstance(prev_tag, Tag)):
prev_tag = prev_tag.previous_sibling
return prev_tag
def find_next(tag):
next_tag = tag.next_sibling
while(not isinstance(next_tag, Tag)):
next_tag = next_tag.next_sibling
return next_tag
Yes the h5 string is Premier League. I will give that a try thanks
– anfield
Nov 22 '18 at 23:03
fixres_item_div seems to only pull one div, any idea why that would be?
– anfield
Nov 23 '18 at 3:08
1
Since you have more than one h5 tag you're trying to find (I misunderstood that), usefind_all
instead offind
, and iterate on the results. I've updated my answer.
– Matt Morgan
Nov 23 '18 at 12:29
That works well, much appreciated.
– anfield
Nov 23 '18 at 14:26
1
done, thanks...
– anfield
Nov 23 '18 at 17:07
|
show 1 more comment
It seems like your challenge is restricting the scraping to just the Premier League
<h5>
and its associated content.
Note: Your question states the
string
of theh5
should bePrem League
, but it in fact appears to bePremier League
when I look at the response.
This HTML appears to be pretty flat and undifferentiated in structure, so it looks like the best thing is to walk through the siblings previous and next from the h5, which is itself fairly easy to locate:
import re
from bs4 import BeautifulSoup, Tag
import requests
prem_league_regex = re.compile(r"Premier League")
def squad_fixtures():
team_table = ['https://www.skysports.com/liverpool-fixtures']
for i in team_table:
squad_r = requests.get(i)
soup = BeautifulSoup(squad_r.text, 'html.parser')
body = soup.find('div', {'class': 'fixres__body'})
h5s = body.find_all('h5', {'class': 'fixres__header3'}, text=prem_league_regex)
for h5 in h5s:
prev_tag = find_previous(h5)
if prev_tag.name == 'h4':
print(prev_tag.text)
prev_tag = find_previous(prev_tag)
if prev_tag.name == 'h3':
print(prev_tag.text)
fixres_item_div = find_next(h5)
"""
get the things you need from fixres__item now that you have it...
"""
def find_previous(tag):
prev_tag = tag.previous_sibling
while(not isinstance(prev_tag, Tag)):
prev_tag = prev_tag.previous_sibling
return prev_tag
def find_next(tag):
next_tag = tag.next_sibling
while(not isinstance(next_tag, Tag)):
next_tag = next_tag.next_sibling
return next_tag
It seems like your challenge is restricting the scraping to just the Premier League
<h5>
and its associated content.
Note: Your question states the
string
of theh5
should bePrem League
, but it in fact appears to bePremier League
when I look at the response.
This HTML appears to be pretty flat and undifferentiated in structure, so it looks like the best thing is to walk through the siblings previous and next from the h5, which is itself fairly easy to locate:
import re
from bs4 import BeautifulSoup, Tag
import requests
prem_league_regex = re.compile(r"Premier League")
def squad_fixtures():
team_table = ['https://www.skysports.com/liverpool-fixtures']
for i in team_table:
squad_r = requests.get(i)
soup = BeautifulSoup(squad_r.text, 'html.parser')
body = soup.find('div', {'class': 'fixres__body'})
h5s = body.find_all('h5', {'class': 'fixres__header3'}, text=prem_league_regex)
for h5 in h5s:
prev_tag = find_previous(h5)
if prev_tag.name == 'h4':
print(prev_tag.text)
prev_tag = find_previous(prev_tag)
if prev_tag.name == 'h3':
print(prev_tag.text)
fixres_item_div = find_next(h5)
"""
get the things you need from fixres__item now that you have it...
"""
def find_previous(tag):
prev_tag = tag.previous_sibling
while(not isinstance(prev_tag, Tag)):
prev_tag = prev_tag.previous_sibling
return prev_tag
def find_next(tag):
next_tag = tag.next_sibling
while(not isinstance(next_tag, Tag)):
next_tag = next_tag.next_sibling
return next_tag
edited Nov 23 '18 at 12:29
answered Nov 22 '18 at 22:53
Matt MorganMatt Morgan
2,2902820
2,2902820
Yes the h5 string is Premier League. I will give that a try thanks
– anfield
Nov 22 '18 at 23:03
fixres_item_div seems to only pull one div, any idea why that would be?
– anfield
Nov 23 '18 at 3:08
1
Since you have more than one h5 tag you're trying to find (I misunderstood that), usefind_all
instead offind
, and iterate on the results. I've updated my answer.
– Matt Morgan
Nov 23 '18 at 12:29
That works well, much appreciated.
– anfield
Nov 23 '18 at 14:26
1
done, thanks...
– anfield
Nov 23 '18 at 17:07
|
show 1 more comment
Yes the h5 string is Premier League. I will give that a try thanks
– anfield
Nov 22 '18 at 23:03
fixres_item_div seems to only pull one div, any idea why that would be?
– anfield
Nov 23 '18 at 3:08
1
Since you have more than one h5 tag you're trying to find (I misunderstood that), usefind_all
instead offind
, and iterate on the results. I've updated my answer.
– Matt Morgan
Nov 23 '18 at 12:29
That works well, much appreciated.
– anfield
Nov 23 '18 at 14:26
1
done, thanks...
– anfield
Nov 23 '18 at 17:07
Yes the h5 string is Premier League. I will give that a try thanks
– anfield
Nov 22 '18 at 23:03
Yes the h5 string is Premier League. I will give that a try thanks
– anfield
Nov 22 '18 at 23:03
fixres_item_div seems to only pull one div, any idea why that would be?
– anfield
Nov 23 '18 at 3:08
fixres_item_div seems to only pull one div, any idea why that would be?
– anfield
Nov 23 '18 at 3:08
1
1
Since you have more than one h5 tag you're trying to find (I misunderstood that), use
find_all
instead of find
, and iterate on the results. I've updated my answer.– Matt Morgan
Nov 23 '18 at 12:29
Since you have more than one h5 tag you're trying to find (I misunderstood that), use
find_all
instead of find
, and iterate on the results. I've updated my answer.– Matt Morgan
Nov 23 '18 at 12:29
That works well, much appreciated.
– anfield
Nov 23 '18 at 14:26
That works well, much appreciated.
– anfield
Nov 23 '18 at 14:26
1
1
done, thanks...
– anfield
Nov 23 '18 at 17:07
done, thanks...
– anfield
Nov 23 '18 at 17:07
|
show 1 more 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%2f53437616%2fbeautifulsoup-find-elements-directly-below-and-above-heading-with-specific-str%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
show your python code
– ewwink
Nov 22 '18 at 21:34
@ewwink - updated and added the code
– anfield
Nov 22 '18 at 22:28