V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
way2explore2
V2EX  ›  Python

想写个爬虫,爬到 form,填表,提交,然而目标站有保护,求助!

  •  
  •   way2explore2 · 2017-06-19 16:09:00 +08:00 · 3109 次点击
    这是一个创建于 2504 天前的主题,其中的信息可能已经有所发展或是发生改变。

    直接不隐讳的直接说了,想写个 python 脚本帮朋友申请签证名额,

    遇到的问题

    1. 每次 get,得到的都是 noscript 的提示,需要 JS
    2. 对于非本地 IP 有验证码

    我的尝试

    mechanize

    import sys
    import mechanize
    url ='xxx'
    response2=br.open(url)
    request = br.request
    print (response2.info())
    print (response2.read())
    

    output:

    Cache-Control: no-store, must-revalidate, no-cache, max-age=0
    Content-Type: text/html
    Connection: close
    Vary: Accept-Encoding
    Pragma: no-cache
    Expires: -1
    CacheControl: no-cache
    X-UA-Compatible: IE=edge
    Content-Type: text/html; charset=utf-8
    
    ... more content ...
    
    <noscript>Please enable JavaScript to view the page content.</noscript>
    </head><body>
    </body></html>
    

    selenium

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    driver = webdriver.Firefox()
    url= 'xxx'
    driver.get(url)
    
    print driver.context
    print driver.title
    
    print driver.page_source
    driver.close()
    

    output

    nosctipt 同上
    

    Refes

    1. 目标站点及详细问题,请见 so https://stackoverflow.com/questions/44562212/fetching-web-page-but-need-javascript-to-view-page-content
    2. 目标 url 在 comment 里
    12 条回复    2023-05-18 15:03:35 +08:00
    golmic
        1
    golmic  
       2017-06-19 16:14:46 +08:00
    怎么登录,需要用户名密码啊。可以帮你看看
    chuanqirenwu
        2
    chuanqirenwu  
       2017-06-19 16:54:19 +08:00
    直接开 selenium 在真机上刷,以前刷论坛是这么做的。
    LeeSeoung
        3
    LeeSeoung  
       2017-06-19 17:02:08 +08:00
    1、需要 JS 要么协议头有问题,要么获取了 cookies,要处理。
    2、对接验证码平台。
    XiaoFaye
        4
    XiaoFaye  
       2017-06-19 17:03:32 +08:00
    楼主,是新西兰的 WHV 签证吧?别爬了,没用的。这个现在只能靠手速和自动填表了。23 号就开抢了,你现在准备也太晚了吧?今年网站已经改版了,表格最新的 DOM 信息有吗?付款页面的 DOM 信息有吗?这些我都有,不过一早已经没兴趣抢了。不过移民政策改了,相信今年抢的人不会那么多了,君不见淘宝的代抢价格已经从 7000 多降到 4000 多了吗?

    最后,祝你朋友好运啦!
    bget
        5
    bget  
       2017-06-20 07:10:10 +08:00
    推荐个爬虫软件你试一下:www.sensite.cn/bget,支持 JS 解析,扩展性强,支持可视化配置。
    prasanta
        6
    prasanta  
       2017-06-21 14:39:44 +08:00 via Android
    你还不如写一个 chrome 插件,自动填表
    way2explore2
        7
    way2explore2  
    OP
       2017-06-21 15:59:26 +08:00
    @XiaoFaye 这对朋友不是中国的,开抢事件不一样
    way2explore2
        8
    way2explore2  
    OP
       2017-06-21 16:00:44 +08:00
    @bget 不是我不想用,只是这 UI 和网站为什么有点很老旧的感觉。
    ![img]( http://www.sensite.cn/images/BgetMainWindow.gif)
    way2explore2
        9
    way2explore2  
    OP
       2017-06-21 16:01:44 +08:00
    @XiaoFaye 另外,Dom 真的不是问题,你看一眼他的 form 你就知道了
    way2explore2
        10
    way2explore2  
    OP
       2017-06-21 16:04:18 +08:00
    @golmic 多谢,我之前申请了一个测试用的账号
    email
    [email protected]
    pwd:
    ieJai3Yae
    way2explore2
        11
    way2explore2  
    OP
       2017-06-21 16:05:14 +08:00
    @chuanqirenwu 我试了 selenium,你说的真机上刷,是指?
    MatrixMan
        12
    MatrixMan  
       345 天前
    老哥有成功过吗?我最近想研究一下,搞一下这个
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1716 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:30 · PVG 00:30 · LAX 09:30 · JFK 12:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.