Crawl Sina Weibo data into MongoDB to avoid repetitive insertion of microblogging data

Source: Internet
Author: User
Tags bulk insert

Def getmydatalist ():
#id这个key
key = str (U ' ID '). decode (' Utf-8 ')
#存储旧数据的id列表
Old_ids = []
#存储新微博的列表
EXTR_WB = []
#从MongoDB上获取的数据
Old_datalist = Weibodata.find ()
For-old in old_datalist:
Old_ids.append (Old[key])

#从微博上抓取新数据
data = Client.statuses.home_timeline.get ()
New_datalist = data.statuses
For new in New_datalist:
If New[key] not in Old_ids:
Extr_wb.append (New)
Weibodata.insert (Extr_wb,save=true)

Ideas:

1. First get the old Weibo data from MongoDB and put all the Weibo data ID into a list old_ids

2. Crawl new data from Weibo and traverse to determine if the Weibo ID is old_ids, then add the microblog to a list that holds the newly inserted data EXTR_WB

3. Perform BULK INSERT INTO MongoDB

Related Article

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.