推荐学习书目
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 · Mar 1, 2018 · 2952 views
    This topic created in 3031 days ago, the information mentioned may be changed or developed.
    例如网址: 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 replies    2018-03-06 20:33:02 +08:00
    nanxung
        1
    nanxung  
       Mar 1, 2018   ❤️ 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
       Mar 6, 2018
    谢谢,我 用 Python 2,还有问题。正在解决中
    ytf513
        3
    ytf513  
    OP
       Mar 6, 2018
    @nanxung 测试了下,好像也没起效,并没有出现现有查询的关键字,而是抓取到了查询主页的内容
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2672 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 14:18 · PVG 22:18 · LAX 07:18 · JFK 10:18
    ♥ Do have faith in what you're doing.