zoukankan      html  css  js  c++  java
  • 豆瓣登陆

    输入验证码个人信息登。。

    import requests
    import html5lib
    import re
    from bs4 import BeautifulSoup
    
    
    s = requests.Session()
    url_login = 'http://accounts.douban.com/login'
    
    formdata = {
        'redir':'https://www.douban.com',
        'form_email': '.......',
        'form_password': '......',
        'login': u'登陆'
    }
    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'}
    
    r = s.post(url_login, data = formdata, headers = headers)
    content = r.text
    soup = BeautifulSoup(content, 'html5lib')
    captcha = soup.find('img', id = 'captcha_image')
    if captcha:
        captcha_url = captcha['src']
        re_captcha_id = r'<input type="hidden" name="captcha-id" value="(.*?)"/'
        captcha_id = re.findall(re_captcha_id, content)
        print(captcha_id)
        print(captcha_url)
        captcha_text = input('Please input the captcha:')
        formdata['captcha-solution'] = captcha_text
        formdata['captcha-id'] = captcha_id
        r = s.post(url_login, data = formdata, headers = headers)
    with open('contacts.txt', 'w+', encoding = 'utf-8') as f:
        f.write(r.text)
  • 相关阅读:
    python函数嵌套的实用技术
    windows10 装linux子系统
    彻底测试全部拷贝list相关操作的区别python
    c语言学习
    Pickling
    Filenames and paths
    Format operator
    Reading and writing
    Persistence
    Automation testing tool comparison
  • 原文地址:https://www.cnblogs.com/chenyang920/p/8060305.html
Copyright © 2011-2022 走看看