"Python" Crawl IMDBTOP250

Source: Internet
Author: User

On the internet to see someone using python+beautifulsoup to crawl the watercress Top250

Try to imitate this and make a crawl of IMDB,

It's only a pity to crawl to 11.

After a long examination,

only to find that

Soup=beautifulsoup (contents) Here, the content is not complete, only until 11 movies.

The code is as follows:

ImportUrllib2 fromBs4Importbeautifulsoupmylist=[]defCrawl (URL): Headers={'user-agent':'mozilla/5.0 (Windows; U Windows NT 6.1;en-us;rv:1.9.1.6) gecko/20091201 firefox/3.5.6'} req=urllib2. Request (url,headers=headers) Page=urllib2.urlopen (req,timeout=200) Contents=page.read () Soup=BeautifulSoup (contents) forTaginchSoup.find_all ('TR', class_={'Odd','even'}): M_order=tag.find ('TD', class_='Titlecolumn'). Span.get_text () M_name=tag.find ('TD', class_='Titlecolumn'). A.get_text () M_rating_score=float (Tag.find ('TD', class_='Ratingcolumn imdbrating'). Strong.get_text ())Print("%s %s%s"%(M_order,m_name,m_rating_score)) Mylist.append ((M_order,m_name,m_rating_score)) Crawl ('Http://www.imdb.com/chart/top?ref_=nv_ch_250_4')        

Later, it seems like you need to use regular expressions to get the crawled pages to work.

But the regular expression has not been manipulated,

If someone sees it, would you like to ask if you can solve the problem by not using regular expressions?

"Python" Crawl IMDBTOP250

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.