1

Thanks to this script:

import requests
from bs4 import BeautifulSoup
import urllib2
import sys  
import urlparse
import io

url = "anUrl"
r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
div = soup.find('div',id='content')
print div.prettify().encode(sys.stdout.encoding, 'ignore')

i've scraped some content that i want to print into another html page, trough javascript how can i handle the python output? Is it possible to print the content in the same way i've done in command line, with a browser page? I've got some encoding problems trying to do that.

1
  • I don't see how Javascript will help you write a new HTML file using Python. Commented Oct 16, 2015 at 16:30

1 Answer 1

2

If you are trying to write the div to an HTML file, then you basically do just that.

f = open('file.html', 'w')
f.write(div)
f.close()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.