Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加个获取用户关注的话题的功能行不? #42

Open
cxgreat2014 opened this issue Jan 29, 2016 · 0 comments
Open

加个获取用户关注的话题的功能行不? #42

cxgreat2014 opened this issue Jan 29, 2016 · 0 comments

Comments

@cxgreat2014
Copy link

加在user类里。。最好把我写的代码改一下再加进去,或者再加个topic类啥的
python
def get_topics_num(self):
if self.user_url == None:
print "I'm anonymous user."
return 0
else:
if self.soup == None:
self.parser()
soup = self.soup
try:
topics_num = soup.find_all("div", class_="zm-profile-side-section-title")[1].strong.string.encode("utf-8")
I=''
for i in topics_num:
if i.isdigit():
I=I+i
topics_num=int(I)
return topics_num
except:
print self.get_user_id()
return 0

def get_topics(self):
    if self.user_url == None:
        print "I'm anonymous user."
        return
    else:
        topics_num = self.get_topics_num()
        print topics_num
        if topics_num == 0:
            return ""
        else:
            for i in xrange((topics_num - 1) / 20 + 1):
                topics_url = self.user_url + "/topics"

                r = requests.get(topics_url)
                lovetopic=""
                soup = BeautifulSoup(r.content)
                for topics in soup.find_all("div", class_="zm-profile-section-item zg-clear"):
                    name =topics.find("strong").string.encode("utf-8")
                    lovetopic=lovetopic+name+"|"
                return lovetopic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants