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