Why isn't it letting me convert a list into a string?












1















I am using BeautifulSoup to scrape the Wikipedia information box and am trying export it into a table



I want to convert my list into a BeatifulSoup in order to be able to use .find_all and .find , to look for the nested tags, but as i did not find anything online to convert, i decided to convert it into a string and then try to convert the string into beautiful soup



When I try to .join my string I get the error:




TypeError: sequence item 0: expected str instance, Tag found.




I have also tried



print (u'').join(unicode(row1) for fow1 in link)
print (u'').join(row1.stripped_strings)


but these give the error




AttributeError: 'NoneType' object has no attribute 'join'




my_table = soup.find('table',{'class':'infobox vcard'})

records =

for my_tables in my_table:
row1 = my_table.find_all('th',{'scope':'row'})
print (row1)

print()

row2 = my_table.find_all('span')
print (row2)

html = ''.join(row1)


It should convert the list into a string










share|improve this question




















  • 2





    Print returns none

    – dennmat
    Jan 1 at 4:57











  • Provide the url you are scraping and your expected the output.

    – salman wahed
    Jan 1 at 5:05






  • 1





    The errors are very descriptive. Look at the beautiful soup docs. You have a list of Tags not strings. And in the other case you're trying to call join on the return of the print method.

    – dennmat
    Jan 1 at 5:32











  • In your code above "row2" is a list of BeautifulSoup Tag elements. You can get the displayed text for the elements with for elem in row2: print(elem.text) and the HTML source with for elem in row2: print(str(elem)) Maybe this helps.

    – Hubert
    Jan 1 at 7:30


















1















I am using BeautifulSoup to scrape the Wikipedia information box and am trying export it into a table



I want to convert my list into a BeatifulSoup in order to be able to use .find_all and .find , to look for the nested tags, but as i did not find anything online to convert, i decided to convert it into a string and then try to convert the string into beautiful soup



When I try to .join my string I get the error:




TypeError: sequence item 0: expected str instance, Tag found.




I have also tried



print (u'').join(unicode(row1) for fow1 in link)
print (u'').join(row1.stripped_strings)


but these give the error




AttributeError: 'NoneType' object has no attribute 'join'




my_table = soup.find('table',{'class':'infobox vcard'})

records =

for my_tables in my_table:
row1 = my_table.find_all('th',{'scope':'row'})
print (row1)

print()

row2 = my_table.find_all('span')
print (row2)

html = ''.join(row1)


It should convert the list into a string










share|improve this question




















  • 2





    Print returns none

    – dennmat
    Jan 1 at 4:57











  • Provide the url you are scraping and your expected the output.

    – salman wahed
    Jan 1 at 5:05






  • 1





    The errors are very descriptive. Look at the beautiful soup docs. You have a list of Tags not strings. And in the other case you're trying to call join on the return of the print method.

    – dennmat
    Jan 1 at 5:32











  • In your code above "row2" is a list of BeautifulSoup Tag elements. You can get the displayed text for the elements with for elem in row2: print(elem.text) and the HTML source with for elem in row2: print(str(elem)) Maybe this helps.

    – Hubert
    Jan 1 at 7:30
















1












1








1


1






I am using BeautifulSoup to scrape the Wikipedia information box and am trying export it into a table



I want to convert my list into a BeatifulSoup in order to be able to use .find_all and .find , to look for the nested tags, but as i did not find anything online to convert, i decided to convert it into a string and then try to convert the string into beautiful soup



When I try to .join my string I get the error:




TypeError: sequence item 0: expected str instance, Tag found.




I have also tried



print (u'').join(unicode(row1) for fow1 in link)
print (u'').join(row1.stripped_strings)


but these give the error




AttributeError: 'NoneType' object has no attribute 'join'




my_table = soup.find('table',{'class':'infobox vcard'})

records =

for my_tables in my_table:
row1 = my_table.find_all('th',{'scope':'row'})
print (row1)

print()

row2 = my_table.find_all('span')
print (row2)

html = ''.join(row1)


It should convert the list into a string










share|improve this question
















I am using BeautifulSoup to scrape the Wikipedia information box and am trying export it into a table



I want to convert my list into a BeatifulSoup in order to be able to use .find_all and .find , to look for the nested tags, but as i did not find anything online to convert, i decided to convert it into a string and then try to convert the string into beautiful soup



When I try to .join my string I get the error:




TypeError: sequence item 0: expected str instance, Tag found.




I have also tried



print (u'').join(unicode(row1) for fow1 in link)
print (u'').join(row1.stripped_strings)


but these give the error




AttributeError: 'NoneType' object has no attribute 'join'




my_table = soup.find('table',{'class':'infobox vcard'})

records =

for my_tables in my_table:
row1 = my_table.find_all('th',{'scope':'row'})
print (row1)

print()

row2 = my_table.find_all('span')
print (row2)

html = ''.join(row1)


It should convert the list into a string







python beautifulsoup wikipedia






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 12:21









HakunaMaData

730418




730418










asked Jan 1 at 4:33









RemmertonRemmerton

164




164








  • 2





    Print returns none

    – dennmat
    Jan 1 at 4:57











  • Provide the url you are scraping and your expected the output.

    – salman wahed
    Jan 1 at 5:05






  • 1





    The errors are very descriptive. Look at the beautiful soup docs. You have a list of Tags not strings. And in the other case you're trying to call join on the return of the print method.

    – dennmat
    Jan 1 at 5:32











  • In your code above "row2" is a list of BeautifulSoup Tag elements. You can get the displayed text for the elements with for elem in row2: print(elem.text) and the HTML source with for elem in row2: print(str(elem)) Maybe this helps.

    – Hubert
    Jan 1 at 7:30
















  • 2





    Print returns none

    – dennmat
    Jan 1 at 4:57











  • Provide the url you are scraping and your expected the output.

    – salman wahed
    Jan 1 at 5:05






  • 1





    The errors are very descriptive. Look at the beautiful soup docs. You have a list of Tags not strings. And in the other case you're trying to call join on the return of the print method.

    – dennmat
    Jan 1 at 5:32











  • In your code above "row2" is a list of BeautifulSoup Tag elements. You can get the displayed text for the elements with for elem in row2: print(elem.text) and the HTML source with for elem in row2: print(str(elem)) Maybe this helps.

    – Hubert
    Jan 1 at 7:30










2




2





Print returns none

– dennmat
Jan 1 at 4:57





Print returns none

– dennmat
Jan 1 at 4:57













Provide the url you are scraping and your expected the output.

– salman wahed
Jan 1 at 5:05





Provide the url you are scraping and your expected the output.

– salman wahed
Jan 1 at 5:05




1




1





The errors are very descriptive. Look at the beautiful soup docs. You have a list of Tags not strings. And in the other case you're trying to call join on the return of the print method.

– dennmat
Jan 1 at 5:32





The errors are very descriptive. Look at the beautiful soup docs. You have a list of Tags not strings. And in the other case you're trying to call join on the return of the print method.

– dennmat
Jan 1 at 5:32













In your code above "row2" is a list of BeautifulSoup Tag elements. You can get the displayed text for the elements with for elem in row2: print(elem.text) and the HTML source with for elem in row2: print(str(elem)) Maybe this helps.

– Hubert
Jan 1 at 7:30







In your code above "row2" is a list of BeautifulSoup Tag elements. You can get the displayed text for the elements with for elem in row2: print(elem.text) and the HTML source with for elem in row2: print(str(elem)) Maybe this helps.

– Hubert
Jan 1 at 7:30














1 Answer
1






active

oldest

votes


















0














print is no longer a statement in Python 3. It's a function. This is also the case in Python 2 if you use from __future__ import print_function Try



print(''.join(str(row1) for fow1 in link))





share|improve this answer
























  • Thanks. I was really stuck

    – Remmerton
    Jan 3 at 10:30













  • It says I don't have enough reputation to upvote, I need at least 15 reputation, or am I doing something really wrong.

    – Remmerton
    Jan 4 at 0:30













  • @Remmerton don't worry about the upvote before you get the rep for it. You should still be able to mark an answer as accepted since you asked the question though.

    – gilch
    Jan 4 at 2:55











  • Sorry didn't see the big tick before.

    – Remmerton
    Jan 5 at 20:38











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993026%2fwhy-isnt-it-letting-me-convert-a-list-into-a-string%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









0














print is no longer a statement in Python 3. It's a function. This is also the case in Python 2 if you use from __future__ import print_function Try



print(''.join(str(row1) for fow1 in link))





share|improve this answer
























  • Thanks. I was really stuck

    – Remmerton
    Jan 3 at 10:30













  • It says I don't have enough reputation to upvote, I need at least 15 reputation, or am I doing something really wrong.

    – Remmerton
    Jan 4 at 0:30













  • @Remmerton don't worry about the upvote before you get the rep for it. You should still be able to mark an answer as accepted since you asked the question though.

    – gilch
    Jan 4 at 2:55











  • Sorry didn't see the big tick before.

    – Remmerton
    Jan 5 at 20:38
















0














print is no longer a statement in Python 3. It's a function. This is also the case in Python 2 if you use from __future__ import print_function Try



print(''.join(str(row1) for fow1 in link))





share|improve this answer
























  • Thanks. I was really stuck

    – Remmerton
    Jan 3 at 10:30













  • It says I don't have enough reputation to upvote, I need at least 15 reputation, or am I doing something really wrong.

    – Remmerton
    Jan 4 at 0:30













  • @Remmerton don't worry about the upvote before you get the rep for it. You should still be able to mark an answer as accepted since you asked the question though.

    – gilch
    Jan 4 at 2:55











  • Sorry didn't see the big tick before.

    – Remmerton
    Jan 5 at 20:38














0












0








0







print is no longer a statement in Python 3. It's a function. This is also the case in Python 2 if you use from __future__ import print_function Try



print(''.join(str(row1) for fow1 in link))





share|improve this answer













print is no longer a statement in Python 3. It's a function. This is also the case in Python 2 if you use from __future__ import print_function Try



print(''.join(str(row1) for fow1 in link))






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 6:13









gilchgilch

4,1851716




4,1851716













  • Thanks. I was really stuck

    – Remmerton
    Jan 3 at 10:30













  • It says I don't have enough reputation to upvote, I need at least 15 reputation, or am I doing something really wrong.

    – Remmerton
    Jan 4 at 0:30













  • @Remmerton don't worry about the upvote before you get the rep for it. You should still be able to mark an answer as accepted since you asked the question though.

    – gilch
    Jan 4 at 2:55











  • Sorry didn't see the big tick before.

    – Remmerton
    Jan 5 at 20:38



















  • Thanks. I was really stuck

    – Remmerton
    Jan 3 at 10:30













  • It says I don't have enough reputation to upvote, I need at least 15 reputation, or am I doing something really wrong.

    – Remmerton
    Jan 4 at 0:30













  • @Remmerton don't worry about the upvote before you get the rep for it. You should still be able to mark an answer as accepted since you asked the question though.

    – gilch
    Jan 4 at 2:55











  • Sorry didn't see the big tick before.

    – Remmerton
    Jan 5 at 20:38

















Thanks. I was really stuck

– Remmerton
Jan 3 at 10:30







Thanks. I was really stuck

– Remmerton
Jan 3 at 10:30















It says I don't have enough reputation to upvote, I need at least 15 reputation, or am I doing something really wrong.

– Remmerton
Jan 4 at 0:30







It says I don't have enough reputation to upvote, I need at least 15 reputation, or am I doing something really wrong.

– Remmerton
Jan 4 at 0:30















@Remmerton don't worry about the upvote before you get the rep for it. You should still be able to mark an answer as accepted since you asked the question though.

– gilch
Jan 4 at 2:55





@Remmerton don't worry about the upvote before you get the rep for it. You should still be able to mark an answer as accepted since you asked the question though.

– gilch
Jan 4 at 2:55













Sorry didn't see the big tick before.

– Remmerton
Jan 5 at 20:38





Sorry didn't see the big tick before.

– Remmerton
Jan 5 at 20:38




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993026%2fwhy-isnt-it-letting-me-convert-a-list-into-a-string%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory