允许从以前的几个url获取html。有时这是需要得到的网页,需要cookies或一个http引用,以获得特定的网页。

html_jumping的Python项目详细描述


欢迎使用HTML跳转

Author:
  • Daniel Perez Rada <@dperezrada>

什么?

允许从以前的几个url获取html。有时这是需要得到的网页,需要cookies或一个http引用,以获得特定的网页。

先决条件

您需要:

要运行测试,您还需要:

  • lxml

示例

无代理

from html_jumping import HtmlJumping
handler = HtmlJumping()
urls = [
    {
        'url': 'http://pypi.python.org/pypi',
        'method': 'GET'
    },
    {
        'url': 'http://pypi.python.org/pypi',
        'method': 'GET',
        'body': {
            'term': 'html_jumping',
            ':action': 'search',
            'submit': 'search'
        }
    }
]
received_header, received_content = handler.get(urls)

代理

允许您使用http代理,您将需要安装socksipy库。

from html_jumping import HtmlJumping
handler = HtmlJumping()
urls = [
    {
        'url': 'http://pypi.python.org/pypi',
        'method': 'GET'
    },
    {
        'url': 'http://pypi.python.org/pypi',
        'method': 'GET',
        'body': {
            'term': 'html_jumping',
            ':action': 'search',
            'submit': 'search'
        }
    }
]
received_header, received_content = handler.get(
    urls,
    proxy_info = {'host': '127.0.0.1', 'port': '8081'}
)

具有永久标题

这将在每次调用中发送标题“accept language”。

from html_jumping import HtmlJumping
handler = HtmlJumping()
urls = [
    {
        'url': 'http://pypi.python.org/pypi',
        'method': 'GET'
    },
    {
        'url': 'http://pypi.python.org/pypi',
        'method': 'GET',
        'body': {
            'term': 'html_jumping',
            ':action': 'search',
            'submit': 'search'
        }
    }
]
received_header, received_content = handler.get(
    urls,
    permanent_headers = {'Accept-Language': 'es, en-cl;q=0.5'}
)

测试

运行

>> nosetests

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用EntityManager有没有更有效的习惯用法?   Android上的java Google应用程序引擎(GAE)响应代码和cookie   如何在Java中创建单元测试?   java从DB获取特定列的最新行   java替换所有悬空元字符   java使用Hibernate删除SQL表中的数据   swing显示JComponent对象Java   java在确认内容类型后如何将URL保存到文件?   javascript如何从段落中选择大量单词?(硒)   java在Linux上使用BundleEnableTiveCode不起作用   java使用日志似然性来比较不同的mallet主题模型?   java无法在Tomcat7上运行Spring Boot 2.0:“由于缺少ServletWebServerFactory bean,无法启动ServletWebServerApplicationContext。”   java有办法显式引用非静态内部类实例吗?   java如何使用Spring的NamedParameterJdbcTemplate在MySQL数据库中创建和删除表?