1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Quora Bot Source Code

Discussion in 'General Programming Chat' started by yellowcat, Jun 22, 2017.

Tags:
  1. yellowcat

    yellowcat Regular Member

    Joined:
    Aug 27, 2015
    Messages:
    305
    Likes Received:
    176
    Location:
    internet 24/7
    Home Page:
    I was able to obtain roughly 1.5 million hits to my questions in a week., i asked roughly 1k questions Mostly just got them from scraping YA and other websites.
    Thought i'd share the source code( it's written in Python 2.7/bs4/selenium)
    [​IMG]

    Code:
    #all cats are yellow
    from selenium import webdriver
    from bs4 import BeautifulSoup
    import time
    
    
    #Quora Login Information
    email=""
    passy=""
    
    # File With Questions Here
    filey = ""
    
    #Read File ,strip new lines ,return question list
    def readFile(filey):
        with open(filey, "r") as f:
            q = f.readlines()
        qlist = [x.strip() for x in q]
        # qlist=reversed(qlist) #Will reverse the question list if needed
        print len(qlist), "Total Questions Loaded"
        return qlist
    
    #Login to Quora
    def login(email, passy):
        print "Logging in..."
        driver.get("http://quora.com")
    
        # Create Soup Object and find all form_column classes
        forms = BeautifulSoup(driver.page_source, "lxml").find_all(class_="form_column")
    
        # Iterate through forms
        # Find polymorphic id string,append a hashtag(#) to create css_selector
        for form in forms:
            try:
                # This is for email/password entry box
                data = form.find("input")["name"]
                if data == "email":
                    email_css = "#" + form.find("input")["id"]
                if data == "password":
                    password_css = "#" + form.find("input")["id"]
            except:
                pass
    
            try:
                # This is for the Login Button
                data = form.find("input")["value"]
                if data == "Login":
                    button_css = "#" + form.find("input")["id"]
            except:
                pass
    
        driver.find_element_by_css_selector(email_css).send_keys(email)
        driver.find_element_by_css_selector(password_css).send_keys(passy)
        time.sleep(2)
        driver.find_element_by_css_selector(button_css).click()
        time.sleep(2)
        # LOGIN FINISHED
    
    
    #Create Question List
    qlist = readFile(filey)
    
    #Create Webdriver Vroom Vroom
    driver = webdriver.Chrome()
    
    #Total Questions Posted Counter
    county=0
    
    # Iterate through qlist ask questions till no more
    for question in qlist:
        try:
            print question
            driver.get("http://quora.com")
            soup=BeautifulSoup(driver.page_source,"lxml")
    
            # Find all text areas
            blox = soup.find_all("textarea")
    
            # Find polymorphic id string for Ask Question entry field
            for x in blox:
                try:
                    placeholder = x["placeholder"]
                    if placeholder.__contains__("Ask or Search Quora"): # Fix this later
                        askbar_css = "#" + x["id"]
                        print askbar_css
                except:
                    pass
    
    
            askbutton = "#" + soup.find(class_="AskQuestionButton")["id"]# Fix this later
    
            # Type out Question
            driver.find_element_by_css_selector(askbar_css).send_keys(question)
    
            # Wait for askbutton to become clickable
            time.sleep(.2) # Fix later
            try:
                driver.find_element_by_css_selector(askbutton).click()
            except:
                #Click Failed # Fix later
                pass
    
            # Find the popup
            while True:
                try:
                    soup = BeautifulSoup(driver.page_source, "lxml")
                    popExists = soup.find(class_="Modal AskQuestionModal")
                    break
                except:
                    pass
            soup = BeautifulSoup(driver.page_source,"lxml")
            popup = "#" + soup.find(class_="submit_button modal_action")["id"]
            driver.find_element_by_css_selector(popup).click()
    
            for x in range(0,17):
                time.sleep(.1)
                try:
                    soup = BeautifulSoup(driver.page_source, "lxml")
                    popExists = soup.find(class_="PMsgContainer") #Found Popup
    
                    if str(popExists).__contains__("You asked"): #big no no
                        county += 1
                        break
                except:
                    pass
            print "county=>",county
    
    
        except Exception,e:
            print e
            print "ERROR"
            pass
    
    Apologies i kinda just wrote it on a whim, then went over it again changed a few things and added some notes. I'd love if anyone could critique my code :)
     
    • Thanks Thanks x 6
    Last edited: Jun 22, 2017
  2. ergoprime

    ergoprime Junior Member

    Joined:
    Nov 3, 2016
    Messages:
    126
    Likes Received:
    19
    Occupation:
    SOCIAL MEDIA MARKETING
    Thanks for the great share! By the way.... what do you gain from that? Can you promote something to your followers? Do you sell your account?

    Obviously I am not very familiar with the marketing opportunities regarding quora, except gaining traffics via links. It would be great if you elaborate further.
     
  3. yellowcat

    yellowcat Regular Member

    Joined:
    Aug 27, 2015
    Messages:
    305
    Likes Received:
    176
    Location:
    internet 24/7
    Home Page:
    I was thinking of creating questions and answers. Answering your own questions on a separate account with links. This would work really well with say "school questions/answers" or other niches. Could also use ask as anonymous to prevent bans.
    Could also be useful for growing upvote accounts
     
  4. ergoprime

    ergoprime Junior Member

    Joined:
    Nov 3, 2016
    Messages:
    126
    Likes Received:
    19
    Occupation:
    SOCIAL MEDIA MARKETING
    Great idea! Now we just need to know the spam regulations of quora (How often can you post links per day per IP without getting banned) and we could drive viral traffic to our sites.

    Thanks again!
     
  5. ergoprime

    ergoprime Junior Member

    Joined:
    Nov 3, 2016
    Messages:
    126
    Likes Received:
    19
    Occupation:
    SOCIAL MEDIA MARKETING
    But I guess that's easy to answer if you experiment a bit.
     
  6. Geasy

    Geasy Jr. VIP Jr. VIP

    Joined:
    Jul 26, 2016
    Messages:
    786
    Likes Received:
    172
    Ohh i miss ubuntu.

    Could i see ur user url jake?

    How it answered question
     
  7. living2xl

    living2xl Jr. VIP Jr. VIP

    Joined:
    Dec 9, 2011
    Messages:
    1,736
    Likes Received:
    415
    Occupation:
    Sippin dat juice - Shout it louder!
    Location:
    Not sleeping!
    Home Page:
    Can you share the YH scrape script plz
     
  8. living2xl

    living2xl Jr. VIP Jr. VIP

    Joined:
    Dec 9, 2011
    Messages:
    1,736
    Likes Received:
    415
    Occupation:
    Sippin dat juice - Shout it louder!
    Location:
    Not sleeping!
    Home Page:
    C:\selenium>C:\selenium\quora.py
    File "C:\selenium\quora.py", line 20
    print len(qlist), "Total Questions Loaded"
    ^
    SyntaxError: invalid syntax


    I use this
    # File With Questions Here
    filey = "questions1.txt"

    What am I doing wrong?
     
  9. xyzhat

    xyzhat Registered Member

    Joined:
    Apr 18, 2016
    Messages:
    61
    Likes Received:
    14
    You may be using a diferent version of Python. Try to download 2.7 version.
    Try using this line if you're using python 3

    Code:
    print(len(qlist), "Total Questions Loaded")
     
    Last edited: Jul 14, 2017
  10. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    3,478
    Likes Received:
    3,108
    Gender:
    Male
    Lovely!
     
  11. shubhamc

    shubhamc Junior Member

    Joined:
    Aug 9, 2015
    Messages:
    106
    Likes Received:
    23
    Hey thanks man :)
     
    • Thanks Thanks x 1
  12. Stiletto

    Stiletto Jr. VIP Jr. VIP

    Joined:
    Nov 5, 2012
    Messages:
    1,429
    Likes Received:
    684
    Location:
    Balkans
    Home Page:
    They're not that strict. I never got my accounts banned but they have deleted 2-3 of my answers probably because they weren't unique, I copied/pasted same answer to multiple questions.
     
  13. apex1

    apex1 Junior Member

    Joined:
    May 29, 2015
    Messages:
    185
    Likes Received:
    153
    Very nice of you to share that OP! Thanks
     
  14. jb2302

    jb2302 Regular Member

    Joined:
    Jun 23, 2015
    Messages:
    403
    Likes Received:
    49
    do quora block ALL other accounts on same IP , if one of them is spamming ?
     
  15. Steveputlocker

    Steveputlocker Regular Member

    Joined:
    Nov 3, 2016
    Messages:
    222
    Likes Received:
    37
    Gender:
    Male
    Can someone Create a quora bot which has following features: -
    1) can upload answers in it (each answer with a link)
    2) Proxy Support
    3) can create accounts on quora, (gmail or other accounts will be provided)
    4) it can post answers just by searching a keyword (will be provided to the bot) on quora using proxies.

    If Yes, then Please PM me
     
  16. aobayomi

    aobayomi Newbie

    Joined:
    Feb 13, 2014
    Messages:
    45
    Likes Received:
    3
    Please anyone willing to reccommend a course that would teach me programming i am interested in creating bots and softwares
     
  17. MaxiPads123

    MaxiPads123 Registered Member

    Joined:
    May 25, 2016
    Messages:
    50
    Likes Received:
    27
    Absolutely beautiful! Thanks for sharing. I'm learning py3 but should be able to use this to help me :)
     
  18. doggysog

    doggysog Registered Member

    Joined:
    Jul 17, 2017
    Messages:
    67
    Likes Received:
    13
    Gender:
    Male
    I don't understand the questions part. how does this bot exactly work and what file should I upload (what should be in it? thank you)
     
  19. yellowcat

    yellowcat Regular Member

    Joined:
    Aug 27, 2015
    Messages:
    305
    Likes Received:
    176
    Location:
    internet 24/7
    Home Page:
    Source codes out dated
     
  20. lelik089

    lelik089 Newbie

    Joined:
    Nov 25, 2017
    Messages:
    6
    Likes Received:
    4
    Gender:
    Male
    thanks man
     
    • Thanks Thanks x 1