小编Ran*_*ins的帖子

将表单数据发送到aspx页面

需要在网站上进行搜索

    url = r'http://www.cpso.on.ca/docsearch/'
Run Code Online (Sandbox Code Playgroud)

这是一个aspx页面(我昨天开始这个艰苦跋涉,抱歉noob问题)

使用BeautifulSoup,我可以像这样得到__VIEWSTATE和__EVENTVALIDATION:

    viewstate = soup.find('input', {'id' : '__VIEWSTATE'})['value']
    eventval = soup.find('input', {'id' : '__EVENTVALIDATION'})['value']
Run Code Online (Sandbox Code Playgroud)

标题可以像这样设置:

    headers = {'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13',
'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml; q=0.9,*/*; q=0.8',
'Content-Type': 'application/x-www-form-urlencoded'}
Run Code Online (Sandbox Code Playgroud)

如果你去网页,我真正想传递的唯一值是名字和姓氏......

    LN = "smith"
    FN = "a"
    data = {"__VIEWSTATE":viewstate,"__EVENTVALIDATION":ev,
    "ctl00$ContentPlaceHolder1$MainContentControl1$ctl00$txtLastName":LN, 
    "ctl00$ContentPlaceHolder1$MainContentControl1$ctl00$txtFirstName":FN}
Run Code Online (Sandbox Code Playgroud)

把所有这些放在一起就像这样:

    import urllib
    import urllib2
    import urlparse
    import BeautifulSoup

    url = r'http://www.cpso.on.ca/docsearch/'
    html = urllib2.urlopen(url).read()
    soup = BeautifulSoup.BeautifulSoup(html)

    viewstate = soup.find('input', {'id' : '__VIEWSTATE'})['value']
    ev = soup.find('input', {'id' : '__EVENTVALIDATION'})['value'] …
Run Code Online (Sandbox Code Playgroud)

python screen-scraping urllib2

6
推荐指数
1
解决办法
2815
查看次数

如何清除ttk.Treeview小部件中的项目?

ing_scroll = Scrollbar(window1_frame1, orient=VERTICAL)
ingredients = ttk.Treeview(window1_frame1, yscrollcommand=ing_scroll.set, height=5, columns=['Ingredient', 'Amount'], show="headings")
ingredients.heading("Ingredient", text='Ingredient')
ingredients.column("Ingredient", width=7)
ingredients.heading("Amount", text='Amount')
ingredients.column("Amount", width=1)
ing_scroll.config(command=ingredients.yview)
ing_scroll.pack(side=RIGHT, fill=Y)
ingredients.pack(side=LEFT, fill='both', expand=1)

def OnRecpSelect(event):
    DB = menu_combo.get()
    mytable = recipe_combo.get()
    ingredient_list = TKengine.pull_ingredients(DB, mytable)
    # NEED TO CLEAR THE INGREDIENTS TTK:TREEVIEW OBJECT HERE!
    for i in ingredient_list: 
        ingre = i[1]
        amoun = i[2]
        value = ingre,amoun
        ingredients.insert('',0,values=value)
Run Code Online (Sandbox Code Playgroud)

ingredient_list是一个显示类似......('Sugar','1 Cup')等等的列表... def用于选择的组合框,所以我想要的是树视图清除而不是只是不断添加更多的成分.不幸的是我没有看到一种clear()方法.

如果有一种程序化的方法来识别那里的东西(列举一个行数会很好......)这让我疯了.我在文档中注意到你可以使用delete方法,但它想知道要删除的项目...如果我使用:

ingredients.delete('',0)
Run Code Online (Sandbox Code Playgroud)

我明白了

TclError: Item 0 not found
Run Code Online (Sandbox Code Playgroud)

所以我认为它需要像'糖'这样的东西......

当然它是一个捕获22因为如果您选择组合框并想要清除成分树视图,相同的成分项目不在每个配方中,那么我们如何知道要删除哪些项目?...

如果您需要更多详细信息,请告诉我...我对使用treeview对象相当新,但它让我想在画布上使用两个列表框.

python syntax treeview tkinter

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

PowerShell:Start-Job,Receive-Job:没有返回值

好的,这是我的脚本

$server=@("SERVER1","SERVER2")
$A=@()

foreach($srv in $server){
    start-job -scriptblock {Get-AppHangs $srv}}

while (Get-Job -State "Running"){}

foreach($JB in Get-Job){$A+=Receive-Job $JB}

Remove-Job *

$A|Out-GridView


function Get-AppHangs($srv){
    $A=@()
    $XX=Get-EventLog -ComputerName $srv -LogName "application" | Where-Object {$_.InstanceID -ge 1000 -and $_.InstanceID -lt 1005} | select -First 5

    foreach($x in $XX){
        $time = $_.Time.ToString()
        $obj=New-Object PSObject
        $obj|Add-Member -MemberType "NoteProperty" -Name Server -Value $srv
        $obj|Add-Member -MemberType "NoteProperty" -Name Index -Value $x.Index
        $obj|Add-Member -MemberType "NoteProperty" -Name Time -Value $x.Time -SecondValue System.string
        $obj|Add-Member -MemberType "NoteProperty" -Name EntryType -Value $x.EntryType …
Run Code Online (Sandbox Code Playgroud)

powershell custom-object start-job

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