duckduckgo.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pydata_webscraping 作者: jmortega 项目源码 文件源码
def create_browser():
    br = mechanize.Browser()           # Create basic browser
    cj = cookielib.LWPCookieJar()      # Create cookiejar to handle cookies
    br.set_cookiejar(cj)               # Set cookie jar for our browser
    br.set_handle_equiv(True)          # Allow opening of certain files
    br.set_handle_gzip(True)           # Allow handling of zip files
    br.set_handle_redirect(True)       # Automatically handle auto-redirects
    br.set_handle_referer(True)
    br.set_handle_robots(False)        # ignore anti-robots.txt

    # Necessary headers to simulate an actual browser
    br.addheaders = [('User-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36'),
                   ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'),
                   ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'),
                   ('Accept-Encoding', 'gzip,deflate,sdch'),
                   ('Accept-Language', 'en-US,en;q=0.8,fr;q=0.6'),
                   ('Connection', 'keep-alive')
                  ]
    return br
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号