本文整理汇总了Python中analyzer.Analyzer.get_childfollowhtml方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.get_childfollowhtml方法的具体用法?Python Analyzer.get_childfollowhtml怎么用?Python Analyzer.get_childfollowhtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.get_childfollowhtml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_follow
# 需要导入模块: from analyzer import Analyzer [as 别名]
# 或者: from analyzer.Analyzer import get_childfollowhtml [as 别名]
def parse_follow(self,response):
item = WeibospiderItem()
analyzer = Analyzer()
getweibopage = GetWeibopage()
total_follow_pq = analyzer.get_childfollowhtml(response.body)
item['uid'] = response.meta['uid']
item['follow_uid_list'] = analyzer.get_childfollow(total_follow_pq)
item['follower_uid_list'] = []
yield item
if self.uid == response.meta['uid'] and len(item['follow_uid_list']):
db = OracleStore()
conn = db.get_connection()
for follow_uid in item['follow_uid_list']:
#获取关注用户的关注用户
sql1 = """select count(*) from t_user_follow where userID=%s""" % str(follow_uid)
cursor1 = db.select_operation(conn,sql1)
count1 = cursor1.fetchone()
follow_scraped = count1[0]
cursor1.close()
if not follow_scraped: #scraped为0,即该账户没有获取过
for page in range(WeiboSpider.follow_page_num,0,-1):
GetWeibopage.relation_data['page'] = page
follow_url = getinfo.get_follow_mainurl(follow_uid) + getweibopage.get_relation_paramurl()
yield Request(url=follow_url,meta={'cookiejar':response.meta['cookiejar'],'uid':follow_uid},callback=self.parse_follow)
else:
print 'follow_uid existed!',follow_uid
yield None
#获取关注用户的粉丝用户
sql2 = """select count(*) from t_user_follower where userID =%s""" % str(follow_uid)
cursor2 = db.select_operation(conn,sql2)
count2 = cursor2.fetchone()
follower_scraped = count2[0]
cursor2.close()
if not follower_scraped: #scraped为0,即该账户没有获取过
for page in range(WeiboSpider.follower_page_num,0,-1):
GetWeibopage.relation_data['page'] = page
follower_url = getinfo.get_follower_mainurl(follow_uid) + getweibopage.get_relation_paramurl()
yield Request(url=follower_url,meta={'cookiejar':response.meta['cookiejar'],'uid':follow_uid},callback=self.parse_follower)
else:
print 'follower_uid existed!',follow_uid
yield None
conn.close()
示例2: parse_follow
# 需要导入模块: from analyzer import Analyzer [as 别名]
# 或者: from analyzer.Analyzer import get_childfollowhtml [as 别名]
def parse_follow(self,response):
item = WeibospiderItem()
analyzer = Analyzer()
total_follow_pq = analyzer.get_childfollowhtml(response.body)
item['uid'] = response.meta['uid']
item['follow_uid_list'] = analyzer.get_childfollow(total_follow_pq)
item['follower_uid_list'] = []
yield item
#获取二级(关注)用户的关注和粉丝
if self.uid == response.meta['uid'] and len(item['follow_uid_list']):
db = OracleStore()
conn = db.get_connection()
for follow_uid in item['follow_uid_list']:
#获取关注用户的关注用户
sql1 = """select count(*) from t_user_follow where userID=%s""" % str(follow_uid)
cursor1 = db.select_operation(conn,sql1)
count1 = cursor1.fetchone()
follow_scraped = count1[0]
cursor1.close()
if not follow_scraped: #scraped为0,即该账户没有获取过
follow_url = 'http://weibo.com/%s/follow?page=1' % str(follow_uid)
yield Request(url=follow_url,meta={'cookiejar':response.meta['cookiejar'],'uid':follow_uid},dont_filter=True,callback=self.parse_based_follownum)
else:
print 'follow_uid existed!',follow_uid
yield None
#获取关注用户的粉丝用户
sql2 = """select count(*) from t_user_follower where userID=%s""" % str(follow_uid)
cursor2 = db.select_operation(conn,sql2)
count2 = cursor2.fetchone()
follower_scraped = count2[0]
cursor2.close()
if not follower_scraped: #scraped为0,即该账户没有获取过
follower_url = 'http://weibo.com/%s/fans?page=1' % str(follow_uid)
yield Request(url=follower_url,meta={'cookiejar':response.meta['cookiejar'],'uid':follow_uid},dont_filter=True,callback=self.parse_based_followernum)
else:
print 'follower_uid existed!',follow_uid
yield None
conn.close()
示例3: parse_based_follownum
# 需要导入模块: from analyzer import Analyzer [as 别名]
# 或者: from analyzer.Analyzer import get_childfollowhtml [as 别名]
def parse_based_follownum(self,response):
item = WeibospiderItem()
analyzer = Analyzer()
total_follow_pq = analyzer.get_childfollowhtml(response.body)
follow_page_num = analyzer.get_relation_pagenum(total_follow_pq)
if follow_page_num != "" and int(follow_page_num) >= 5:
for page in range(5,0,-1):
GetWeibopage.relation_data['page'] = page
follow_url = getinfo.get_follow_mainurl(response.meta['uid']) + WeiboSpider.getweibopage.get_relation_paramurl()
yield Request(url=follow_url,meta={'cookiejar':response.meta['cookiejar'],'uid':response.meta['uid']},callback=self.parse_follow)
elif follow_page_num == "":
follow_url = 'http://weibo.com/%s/follow?page=1' % response.meta['uid']
yield Request(url=follow_url,meta={'cookiejar':1,'uid':response.meta['uid']},callback=self.parse_follow)
else:
for page in range(int(follow_page_num),0,-1):
GetWeibopage.relation_data['page'] = page
follow_url = getinfo.get_follow_mainurl(response.meta['uid']) + WeiboSpider.getweibopage.get_relation_paramurl()
yield Request(url=follow_url,meta={'cookiejar':response.meta['cookiejar'],'uid':response.meta['uid']},callback=self.parse_follow)