相关疑难解决方法(0)

使用urllib下载pdf?

我想使用urllib从网站下载pdf文件.这是我到目前为止所得到的:

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')
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我得到的只是一个空的pdf文件.我究竟做错了什么?

python pdf urllib

18
推荐指数
3
解决办法
4万
查看次数

如何使用Chrome中的Selenium + Python绑定控制文件下载

在哪里可以找到描述我可以与Selenium和Chrome网络浏览器一起使用的选项的文档?我想在Web浏览器中打开一个链接(获取凭据)但不要下载相应的文件(.pdf或.tiff或.jpeg).我在Windows 7笔记本电脑上使用Python 2.7,selenium 3.0.1和Chrome版本54.0.2840.99(以及chromedriver.exe).

# Chrome web browser.
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')  
#options.add_argument('--disable-download-notification') #doesn't seems to work 
#options.add_experimental_option("prefs", {"download.default_directory","C:\Users\xxx\downloads\Test"}) # doesn't work
#options.add_experimental_option("prefs", {"download.prompt_for_download": False}) # doesn't seems to work
#options.add_experimental_option("prefs", {'profile.default_content_settings': {'images': 2}})# this will disable image loading in the browser
options.add_argument("user-agent="+user_agent_profile)
driver_main = webdriver.Chrome(chrome_options=options)

# Opening the web application portail.
driver_main.get("https://my_link")
Run Code Online (Sandbox Code Playgroud)

我找到了很多关于这个主题的讨论,但没有一个解决方案有效.例如:

add_experimental_option("prefs", {"download.default_directory","C:\Users\xxx\downloads\Test"})
Run Code Online (Sandbox Code Playgroud)

不适合我.

同样的:

add_experimental_option("prefs", {"download.prompt_for_download": False})
Run Code Online (Sandbox Code Playgroud)

(我也尝试"假").

而:

add_argument("user-agent="+user_agent_profile)
Run Code Online (Sandbox Code Playgroud)

似乎工作!

我不确定是什么问题

我得到的问题是,每当我打开名称文件(1)文件(2)....文件(99)的链接时,它开始下载文件,然后从100开始,它会打开一个弹出窗口"另存为" .所以我想要么根本不下载文件或者能够将它移动到"回收站"中的特定文件夹中.

如何找到与add_argument和add_argument一起使用的选项?我试着看看Chrome://关于/但我看不到直接的信件.

非常感谢.

干杯.

法比安.

google-chrome file download python-2.7 selenium-webdriver

8
推荐指数
1
解决办法
2万
查看次数

为什么在 Selenium 中使用 add_experimental_option?

我试图理解一个与以下内容非常相似的代码片段:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
port_number = "127.0.0.1.8888"
chrome_options.add_experimental_option("someAddressName", port_number)
Run Code Online (Sandbox Code Playgroud)

我试图寻找解释,但直到现在还没有得到任何满意的答案。有人可以解释的任务Options()add_experimental_option特别?

谢谢你

selenium python-2.7 selenium-chromedriver

0
推荐指数
1
解决办法
4767
查看次数