urllib

Javascript access another webpage

╄→гoц情女王★ 提交于 2019-11-28 23:46:59
I know very, very little of javascript, but I'm interested in writing a script which needs information from another webpage. It there a javascript equivalent of something like urllib2? It doesn't need to be very robust, just enough to process a simple GET request, no need to store cookies or anything and store the results. Daniel Vassallo There is the XMLHttpRequest , but that would be limited to the same domain of your web site, because of the Same Origin Policy . However, you may be interested in checking out the following Stack Overflow post for a few solutions around the Same Origin Policy

urllib.quote() throws KeyError

纵然是瞬间 提交于 2019-11-28 22:04:21
问题 To encode the URI, I used urllib.quote("schönefeld") but when some non-ascii characters exists in string, it thorws KeyError: u'\xe9' Code: return ''.join(map(quoter, s)) My input strings are köln, brønshøj, schönefeld etc. When I tried just printing statements in windows(Using python2.7, pyscripter IDE). But in linux it raises exception (I guess platform doesn't matter). This is what I am trying: from commands import getstatusoutput queryParams = "schönefeld"; cmdString = "http://baseurl" +

Python: Clicking a button with urllib or urllib2

我是研究僧i 提交于 2019-11-28 21:40:48
I want to click a button with python, the info for the form is automatically filled by the webpage. the HTML code for sending a request to the button is: INPUT type="submit" value="Place a Bid"> How would I go about doing this? Is it possible to click the button with just urllib or urllib2? Or will I need to use something like mechanize or twill? Use the form target and send any input as post data like this: <form target="http://mysite.com/blah.php" method="GET"> ...... ...... ...... <input type="text" name="in1" value="abc"> <INPUT type="submit" value="Place a Bid"> </form> Python: # parse

How to auto log into gmail atom feed with Python?

吃可爱长大的小学妹 提交于 2019-11-28 20:50:26
Gmail has this sweet thing going on to get an atom feed: def gmail_url(user, pwd): return "https://"+str(user)+":"+str(pwd)+"@gmail.google.com/gmail/feed/atom" Now when you do this in a browser, it authenticates and forwards you. But in Python, at least what I'm trying, isn't working right. url = gmail_url(settings.USER, settings.PASS) print url opener = urllib.FancyURLopener() f = opener.open(url) print f.read() Instead of forwarding correctly, it's doing this: >>> https://user:pass@gmail.google.com/gmail/feed/atom Enter username for New mail feed at mail.google.com: This is BAD! I shouldn't

'module' has no attribute 'urlencode'

扶醉桌前 提交于 2019-11-28 20:45:25
问题 When I try to follow the Python Wiki's example related to URL encoding: >>> import urllib >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) >>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query", params) >>> print f.read() An error is raised on the second line: Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'urlencode' What am I missing? 回答1: urllib has been split up in Python 3 . The urllib

Force python mechanize/urllib2 to only use A requests?

二次信任 提交于 2019-11-28 19:42:38
Here is a related question but I could not figure out how to apply the answer to mechanize/urllib2: how to force python httplib library to use only A requests Basically, given this simple code: #!/usr/bin/python import urllib2 print urllib2.urlopen('http://python.org/').read(100) This results in wireshark saying the following: 0.000000 10.102.0.79 -> 8.8.8.8 DNS Standard query A python.org 0.000023 10.102.0.79 -> 8.8.8.8 DNS Standard query AAAA python.org 0.005369 8.8.8.8 -> 10.102.0.79 DNS Standard query response A 82.94.164.162 5.004494 10.102.0.79 -> 8.8.8.8 DNS Standard query A python.org

replace special characters in a string python

若如初见. 提交于 2019-11-28 19:41:10
I am using urllib to get a string of html from a website and need to put each word in the html document into a list. Here is the code I have so far. I keep getting an error. I have also copied the error below. import urllib.request url = input("Please enter a URL: ") z=urllib.request.urlopen(url) z=str(z.read()) removeSpecialChars = str.replace("!@#$%^&*()[]{};:,./<>?\|`~-=_+", " ") words = removeSpecialChars.split() print ("Words list: ", words[0:20]) Here is the error. Please enter a URL: http://simleyfootball.com Traceback (most recent call last): File "C:\Users\jeremy.KLUG\My Documents

How to convert a dictionary to query string in Python?

不羁的心 提交于 2019-11-28 17:41:46
After using cgi.parse_qs() , how to convert the result (dictionary) back to query string? Looking for something similar to urllib.urlencode() . Ignacio Vazquez-Abrams Python 3 urllib.parse. urlencode (query, doseq=False, [...]) Convert a mapping object or a sequence of two-element tuples, which may contain str or bytes objects, to a percent-encoded ASCII text string. — Python 3 urllib.parse docs A dict is a mapping. Legacy Python urllib.urlencode ( query [, doseq ]) Convert a mapping object or a sequence of two-element tuples to a “percent-encoded” string... a series of key=value pairs

Can’t download youtube video

你说的曾经没有我的故事 提交于 2019-11-28 17:20:11
I’m having trouble retrieving the Youtube video automatically. Here’s the code. The problem is the last part. download = urllib.request.urlopen(download_url).read() # Youtube video download script # 10n1z3d[at]w[dot]cn import urllib.request import sys print("\n--------------------------") print (" Youtube Video Downloader") print ("--------------------------\n") try: video_url = sys.argv[1] except: video_url = input('[+] Enter video URL: ') print("[+] Connecting...") try: if(video_url.endswith('&feature=related')): video_id = video_url.split('www.youtube.com/watch?v=')[1].split('&feature

Making HTTP POST request

穿精又带淫゛_ 提交于 2019-11-28 17:09:19
问题 I'm trying to make a POST request to retrieve information about a book. Here is the code that returns HTTP code: 302, Moved import httplib, urllib params = urllib.urlencode({ 'isbn' : '9780131185838', 'catalogId' : '10001', 'schoolStoreId' : '15828', 'search' : 'Search' }) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn = httplib.HTTPConnection("bkstr.com:80") conn.request("POST", "/webapp/wcs/stores/servlet/BuybackSearch", params, headers)