Sep-02-2017, 04:49 AM
(This post was last modified: Sep-02-2017, 04:58 AM by thomas2004ch.)
This help! The login page is coming out.
I replace the 'Foo' with my email address and 'Bar' with my lastname. It is logged in!
And here is what I got:
C:\ProgramData\Anaconda3>python.exe log_test.py
Welcome to the Technical Analysis of STOCKS & COMMODITIES Subscribers’ Area
Now I concat the code for downloading. But the PDF cannot be downloaded correctly as before. Here is my whole code:
I think maybe we have to simulate the input of the PDF-Url and the clicking of download/save with Selenium?
I replace the 'Foo' with my email address and 'Bar' with my lastname. It is logged in!
And here is what I got:
C:\ProgramData\Anaconda3>python.exe log_test.py
Welcome to the Technical Analysis of STOCKS & COMMODITIES Subscribers’ Area
Now I concat the code for downloading. But the PDF cannot be downloaded correctly as before. Here is my whole code:
""" Spyder Editor This is a temporary script file. """ from selenium import webdriver from bs4 import BeautifulSoup import time import urllib.request caps = webdriver.DesiredCapabilities().FIREFOX caps["marionette"] = True browser = webdriver.Firefox(capabilities=caps) web_url = 'http://technical.traders.com/sub/sublogin2.asp' browser.get(web_url) user_name = browser.find_element_by_css_selector('#SubID > input[type="text"]') user_name.send_keys("[email protected]") password = browser.find_element_by_css_selector('#SubName > input[type="text"]') password.send_keys("MyLastname") time.sleep(2) submit = browser.find_element_by_css_selector('#SubButton > input[type="submit"]') submit.click() time.sleep(2) # Give source code to BeautifulSoup soup = BeautifulSoup(browser.page_source, 'lxml') log_in = soup.find('h2') print(log_in.text) time.sleep(2) def download_file(download_url, fileName): print(download_url) response = urllib.request.urlopen(download_url) file = open(fileName, 'wb') print(response) file.write(response.read()) file.close() response.close() print("Completed") urlstr = "http://technical.traders.com/archive/article.asp?file=\V26\C07\131INTR.pdf" download_file(urlstr, "D:\\eBooks\\Stocks_andCommodities\\2008\\Jul\\mypdf.pdf")
I think maybe we have to simulate the input of the PDF-Url and the clicking of download/save with Selenium?