python - Convert cURL to urllib request -
i have curl
curl 'http://www.gocomics.com/search?search_string=garfield' -h 'host: www.gocomics.com' -h 'user-agent: mozilla/5.0 (x11; ubuntu; linux x86_64; rv:38.0) gecko/20100101 firefox/38.0' -h 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -h 'accept-language: en-us,en;q=0.5' --compressed -h 'cookie: _gocomics3_session=bah7cekid3nlc3npb25fawqgogzfrkkijti3ytq1nzy3nmjjmjjhywuwndfjodnjmjviyzy1mmqybjsavekidnjldhvybl90bwy7aeyiiy9zzwfyy2g%2fc2vhcmnox3n0cmluzz1nyxjmawvszekief9jc3jmx3rva2vubjsarkkimtbzrjhmawllb3ltrwm5y05naujntfzhmmzkaehxtenpm29nsms3stvry2c9bjsarg%3d%3d--1ec4e3b379629daf62427da9b4bbe7466b71048e; _ga=ga1.2.1017055044.1433399187; __atuvc=6%7c22; __atuvs=556fef9281e9c25a005; __atssc=google%3b2; __qca=p0-1022399293-1433399204316; _gat_trackeruu4=1' -h 'connection: keep-alive' -h 'if-none-match: "d7a8fc41bab9afc05623db6a7741ef11"'
how put parameters in urllib request in python?
import urllib2 req = urllib2.request('http://www.gocomics.com/search?search_string=garfield') req.add_header('host', 'host: www.gocomics.com') req.add_header('user-agent', 'user-agent: mozilla/5.0 (x11; ubuntu; linux x86_64; rv:38.0) gecko/20100101 firefox/38.0') req.add_header('accept', 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') req.add_header('accept-language', 'accept-language: en-us,en;q=0.5') req.add_header('cookie', 'cookie: _gocomics3_session=bah7cekid3nlc3npb25fawqgogzfrkkijti3ytq1nzy3nmjjmjjhywuwndfjodnjmjviyzy1mmqybjsavekidnjldhvybl90bwy7aeyiiy9zzwfyy2g%2fc2vhcmnox3n0cmluzz1nyxjmawvszekief9jc3jmx3rva2vubjsarkkimtbzrjhmawllb3ltrwm5y05naujntfzhmmzkaehxtenpm29nsms3stvry2c9bjsarg%3d%3d--1ec4e3b379629daf62427da9b4bbe7466b71048e; _ga=ga1.2.1017055044.1433399187; __atuvc=6%7c22; __atuvs=556fef9281e9c25a005; __atssc=google%3b2; __qca=p0-1022399293-1433399204316; _gat_trackeruu4=1') req.add_header('connection', 'connection: keep-alive') req.add_header('if-none-match', 'if-none-match: "d7a8fc41bab9afc05623db6a7741ef11"') resp = urllib2.urlopen(req) content = resp.read()
Comments
Post a Comment