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
ytf513
V2EX  ›  Python

怎么爬取 window.open 中打开的网页,参数用 escape 包了

  •  
  •   ytf513 · 2018-03-01 11:38:33 +08:00 · 2068 次点击
    这是一个创建于 2246 天前的主题,其中的信息可能已经有所发展或是发生改变。
    例如网址: http://hr.bjx.com.cn/SearchResult.aspx

    params = {'keyWord': input_str, 'function2': '', 'function1': '','class1': '', 'class2': '', 'workprovince': '', 'record': 0, 'workTime': 0,'chkabove': '', 'page': i}
    r=requests.get('http://hr.bjx.com.cn/SearchResult.aspx',headers=headers_input,params=params,timeout=5) #params=params 时会出错
    r.encoding = r.apparent_encoding #从内容分析出的响应内容编码方式
    resp_text=r.text

    如果 ·input_str· 为中文则搜索失败,为英文是 OK 的。
    3 条回复    2018-03-06 20:33:02 +08:00
    nanxung
        1
    nanxung  
       2018-03-01 17:21:48 +08:00   ❤️ 1
    看了下你的问题,中文可参考下面代码


    import requests
    headers_input={
    "user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"
    }
    k=str("运维".encode('unicode-escape'))
    k=k.replace("\\\\","%")
    print(k)
    u="http://hr.bjx.com.cn/SearchResult.aspx?keyword={}&function1=&function2=&class1=&class2=&record=0&workTime=0&workprovince=&chkabove=".format(k)
    params = {'keyWord': k.upper(), 'function2': '', 'function1': '','class1': '', 'class2': '', 'workprovince': '', 'record': 0, 'workTime': 0,'chkabove': '', 'page': 1}
    r=requests.get(u,headers=headers_input,timeout=5) #params=params 时会出错
    r.encoding = r.apparent_encoding #从内容分析出的响应内容编码方式
    resp_text=r.text
    print(r.text)
    ytf513
        2
    ytf513  
    OP
       2018-03-06 20:11:24 +08:00
    谢谢,我 用 Python 2,还有问题。正在解决中
    ytf513
        3
    ytf513  
    OP
       2018-03-06 20:33:02 +08:00
    @nanxung 测试了下,好像也没起效,并没有出现现有查询的关键字,而是抓取到了查询主页的内容
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5310 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:35 · PVG 16:35 · LAX 01:35 · JFK 04:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.