urllib

Python: Clicking a button with urllib or urllib2

风流意气都作罢 提交于 2019-11-27 14:05:09
问题 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? 回答1: Use the form target and send any input as post data like this: <form target="http://mysite.com/blah.php" method="GET"> ...... ...... ......

pyhton学习——包

冷暖自知 提交于 2019-11-27 14:03:05
包:文件夹中有一个__init__.py文件 包:是几个模块的集合 # from import # from glance.api import pickle # from glance.api.policy import get 直接导入包 # import glance 导入一个包 不意味着这个包下面的所有内容都是可以被使用的 导入一个包到底发生了什么? 相当于执行了这个包下面的__init__.py文件 绝对导入 优点: 在执行一个py脚本的时候,这个脚本以及和这个脚本同级的模块中只能用绝对写入 缺点: 1.所有的导入都要从一个根目录下往后解释文件夹之间的关系 2.如果当前导入包的文件和被导入的包的位置关系发上了变化那么所有的__init__文件都要做相应的调整 相对导入: 优点: 不需要去反复的修改路径,只要一个包中的所有文件夹和文件的相对位置不发生改变也不需要去关心当前这个包和被执行的文件之间的层级关系 缺点 含有相对导入的py文件不能被直接执行,必须要放在包中被导入的调用才能执行#如果只是从包中导入模块的话,我们不需要做任何操作,直接导入就行 import urllib 报错,说明urllib是个包,不能直接用resquest.py文件 url.request from urllib import request# request正确导入方法 来源: https:/

How to auto log into gmail atom feed with Python?

孤街醉人 提交于 2019-11-27 13:27:22
问题 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

no module named urllib.parse (How should I install it?)

狂风中的少年 提交于 2019-11-27 13:02:06
I'm trying to run a REST API on CentOS 7, I read urllib.parse is in Python 3 but I'm using Python 2.7.5 so I don't know how to install this module. I installed all the requirements but still can't run the project. When I'm looking for a URL I get this (I'm using the browsable interface): Output: ImportError at /stamp/ No module named urllib.parse Agnaldo Marinho If you need to write code which is Python2 and Python3 compatible you can use the following import try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse You want urlparse using python2: from urlparse

Download pdf using urllib?

跟風遠走 提交于 2019-11-27 12:49:40
I am trying to download a pdf file from a website using urllib. This is what i got so far: import urllib def download_file(download_url): web_file = urllib.urlopen(download_url) local_file = open('some_file.pdf', 'w') local_file.write(web_file.read()) web_file.close() local_file.close() if __name__ == 'main': download_file('http://www.example.com/some_file.pdf') When i run this code, all I get is an empty pdf file. What am I doing wrong? jamiemcg Here is an example that works: import urllib2 def main(): download_file("http://mensenhandel.nl/files/pdftest2.pdf") def download_file(download_url):

SSL: CERTIFICATE_VERIFY_FAILED with Python3

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 12:02:33
I apologize if this is a silly question, but I have been trying to teach myself how to use BeautifulSoup so that I can create a few projects. I was following this link as a tutorial: https://www.youtube.com/watch?v=5GzVNi0oTxQ After following the exact same code as him, this is the error that I get: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1240, in do_open h.request(req.get_method(), req.selector, req.data, headers) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line

How to convert a dictionary to query string in Python?

不羁岁月 提交于 2019-11-27 10:55:11
问题 After using cgi.parse_qs() , how to convert the result (dictionary) back to query string? Looking for something similar to urllib.urlencode() . 回答1: 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

Python学习:使用urllib模块读取网络资源及提交请求

烈酒焚心 提交于 2019-11-27 10:38:19
request 还是requests ? 来自Python小白真诚的求助!没办法,只能求助Google了! 原来,Requests模块是一个用于网络访问的模块,网络访问就是利用某些参数发送请求,然后获取我们想要的信息。其实类似的模块有很多,比如urllib,urllib2,httplib,httplib2,他们基本都提供相似的网络访问功能。 初学Python,虽然语法不算难,挺好学的,但是第三方模块太多了,各个模块功能都超级强大。想要靠自己完全掌握Python有点难,网上找了一个Python urllib模块的小视频,我觉得讲的超详细,特来分享给大家~ 如果你也想掌握Python并发编程+网络编程相关的知识,跟我一起看看下方视频,听老师讲解答Python urllib模块是如何读取网络资源及提交请求的。 并发编程+网络编程 李刚老师出版的《疯狂Java》系列图书曾得到市场的广泛认可,经过多次再版,并被多家高校选作教材。上方视频来自于李刚老师的在线视频课程《21天通关Python》 第八章 并发编程+网络编程 鉴于大家都有学习Python的困惑,今天就给大家推荐一本巨有影响力的Python实战书,上线时间仅2个月,就超越了众多实力派,成京东和当当网上的长期畅销图书,并且收获了3.4W的五星好评。 这本书可谓是笔者独家私藏图书之一了,对我学习Python有着莫大的帮助,在京东上也常常

Can’t download youtube video

荒凉一梦 提交于 2019-11-27 10:23:56
问题 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

url编码与解码

穿精又带淫゛_ 提交于 2019-11-27 10:04:26
为何要将URL地址进行编码 然后发送到服务器端? 协议规范: RFC 1738 ,定义了,url地址中,不能包含,除了,0-9的数字,大小写字母(a-zA-Z),短横线’-’之外的字母,但是我们的URL中不止这些字符还有一些特殊字符 比如$-_.+!*’(), 这时候就需要我们进行编码传输。编码很简单, 就是将其值变为%xx而已,而xx就是该字符的16进制值而已。下面的表取自百度百科,大家可以参考一下。 backspace %08 I %49 v %76 ó %D3 tab %09 J %4A w %77 Ô %D4 linefeed %0A K %4B x %78 Õ %D5 creturn %0D L %4C y %79 Ö %D6 space %20 M %4D z %7A Ø %D8 ! %21 N %4E { %7B ù %D9 " %22 O %4F | %7C ú  %DA # %23 P %50 } %7D Û %DB $ %24 Q %51 ~ %7E ü %DC % %25 R %52 ¢ %A2 Y %DD & %26 S %53 £ %A3 T %DE ' %27 T %54 ¥ %A5 ß %DF ( %28 U %55 | %A6 à %E0 ) %29 V %56 § %A7 á %E1 * %2A W %57 « %AB a %E2 + %2B X