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