使用Python 3.3.3从受密码保护的网页检索数据

时间:2015-02-12 14:22:50

标签: python passwords urllib python-3.3

我正在尝试使用urllib访问网站,然后剥离页面源,以便我可以从中收集一些数据。我知道如何为公共网站执行此操作,但我不知道如何使用urllib为受密码保护的网页执行此操作。我知道用户名和密码,我对如何让urllib输入正确的凭据然后重新路由到我想要从中删除数据的正确页面感到非常困惑。目前,我的代码看起来像这样。问题是它正在调出登录页面的来源。

from tkinter import *
import csv
from re import findall
import urllib.request
    def info():    

        file = filedialog.askopenfilename()
        fileR = open(file, 'r')
        hold = csv.reader(fileR, delimiter=',', quotechar='|')
        aList=[]
        for item in hold:
            if item[1] and item[2] == "":
                print(item[1])
                url = "www.example.com/id=" + item[1]
                request = urllib.request.urlopen(url)
                html = request.read()
                data = str(html)
                person = findall('''\$MainContent\$txtRecipient\"\stype=\"text\"\svalue=\"([^\"]+)\"''',data)
            else:
                pass

        fileR.close

请记住,我正在使用python 3.3.3。任何帮助将不胜感激!

0 个答案:

没有答案