[BangPypers] Newspaper in Python

Nimish Dalal nimish.s.dalal at gmail.com
Fri Apr 24 09:47:37 CEST 2015


On Fri, Apr 24, 2015 at 12:21 PM, Dhawal Joharapurkar <dmjan21 at gmail.com>
wrote:

> This is a simple problem.
>
> 1. Create a file handle.
> 2. Write to the file using the file handle.
> 3. Close the file handle.
>
> import newspaper
> outfile = open('outfile.txt', 'a+)  # Create a file handle
>
> Sc_paper = newspaper.build(u'http://scroll.in/')
> for article in Sc_paper.articles:
>     print(article.url)
>     outfile.write(article)  # Write to file
>     outfile.write('\n')
>
> outfile.close()  # Close the file handle
>

Thanks Dhawal, I tried this code and it gives me a Type error
import newspaper
outfile = open('I:\Python\outfile.txt', 'a+')  # Create a file handle

Sc_paper = newspaper.build(u'http://scroll.in/')
for article in Sc_paper.articles:
    print(article.url)
    outfile.write(article)  # Write to file
    outfile.write('\n')
outfile.close()

 TypeError: expected a character buffer object.




> On Fri, Apr 24, 2015 at 12:16 PM, Nimish Dalal <nimish.s.dalal at gmail.com>
> wrote:
>
> > Hi, I am new to python and need help with newspaper.
> > I am using this module as I find it easier to extract the urls from the
> > website.
> >
> > Here's my code:
> >
> > import newspaper
> > Sc_paper = newspaper.build(u'http://scroll.in/')
> > for article in Sc_paper.articles:
> >     print(article.url)
> > http://scroll.in/...
> > http://scroll.in/...
> >
> > Instead of  print I want the urls to export as a .txt file or .csv file.
> >
> > Thanks in advance.
> >
> >
> > --
> > Nimish S. Dalal
> > Cell: 9819670499
> > Facebook: http://www.facebook.com/nimish.s.dalal
> > Twitter: http://twitter.com/nimishdalal <http://twitter.com/nimishsdalal
> >
> > Linkedin:http://in.linkedin.com/in/nimishsdll
> > Url: http://www.nimishdalal.me
> >
> > Our generation has had no Great Depression, no Great War. Our war is a
> > spiritual war. Our great depression is our lives.
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > https://mail.python.org/mailman/listinfo/bangpypers
> >
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>



-- 
Nimish S. Dalal
Cell: 9819670499
Facebook: http://www.facebook.com/nimish.s.dalal
Twitter: http://twitter.com/nimishdalal <http://twitter.com/nimishsdalal>
Linkedin:http://in.linkedin.com/in/nimishsdll
Url: http://www.nimishdalal.me

Our generation has had no Great Depression, no Great War. Our war is a
spiritual war. Our great depression is our lives.


More information about the BangPypers mailing list