小编pau*_*aul的帖子

Python的机械化代理支持

我有一个关于python mechanize的代理支持的问题.我正在制作一些Web客户端脚本,我想在我的脚本中插入代理支持功能.

例如,如果我有:

params = urllib.urlencode({'id':id, 'passwd':pw})
rq = mechanize.Request('http://www.example.com', params) 
rs = mechanize.urlopen(rq)
Run Code Online (Sandbox Code Playgroud)

如何在我的机械化脚本中添加代理支持?每当我打开这个www.example.com网站,我希望它通过代理.

python mechanize

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

python mechanize.browser submit()相关问题

我用mechanize.browser模块制作一些脚本.

其中一个问题是所有其他的东西都可以,但是当提交()表单时,它不起作用,

所以我发现了一些怀疑来源部分.

在html源代码中我被发现如下.

<form method="post" onsubmit="return loginCheck(this)" name="FRMLOGIN"/>
Run Code Online (Sandbox Code Playgroud)

即时通讯思考,loginCheck(this)提交表单时出现问题.

但是如何用机械化模块处理这种javascript函数,所以我可以

成功提交表格并可以收到结果?

folloing是我目前的脚本来源.

如果有人可以帮助我..很欣赏!!

# -*- coding: cp949-*-
import sys,os
import mechanize, urllib
import cookielib
from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup,Tag
import datetime, time, socket
import re,sys,os,mechanize,urllib,time


br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# Want debugging messages?
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 …
Run Code Online (Sandbox Code Playgroud)

python mechanize

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

列表管理python

我已经提取了一些网址列表,并希望操纵此列表.以下是提取列表示例:

http://help.naver.com/service/svc_index.jsp?selected_nodeId=NODE0000000235
http://www.naver.com/rules/service.html
http://news.naver.com/main/principle.nhn
http://www.naver.com/rules/privacy.html
http://www.naver.com/rules/disclaimer.html
http://help.naver.com/claim_main.asp
http://news.naver.com/main/ombudsman/guidecenter.nhn?mid=omb
http://www.nhncorp.com/
http://www.nhncorp.com/
Run Code Online (Sandbox Code Playgroud)

我想只提取以' http://www.naver.com ' 开头的网址,所以最后我想要的列表如下

http://www.naver.com/rules/privacy.html
http://www.naver.com/rules/disclaimer.html
http://www.naver.com/rules/service.html
Run Code Online (Sandbox Code Playgroud)

我怎样才能提取我想要的东西?

python

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

VB到Delphi字符串操作代码转换

我有一些VB源代码,并希望将其转换为Delphi:

Do While Not EOF(textfile)
Line Input #textfile, Line

Dim retstring() As String         
retstring = Split(Line, Chr(32))
first  = retstring(0)
second = retstring(1)
Run Code Online (Sandbox Code Playgroud)

我有一些文本文件与这些类似的行:

hello all
nice to
good day

我在答案中尝试了一些源代码,但仍然遇到问题.我看到消息'你好'和'很好',但实际上我想看到'你好'和'全'而不是.

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  list : TStringList;
  first, second, third: string;
begin
  list := TStringList.Create;
  try
    list.Delimiter := #32;
    list.LoadFromFile('test.txt');
    first := list[0];
    second := list[1];
    ShowMessage(first);
    ShowMessage(second);
  finally
    list.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

delphi text-manipulation

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

python cx_freeze问题ascil

我想用py2exe或制作EXE文件cx_freeze.

所以我试着用py2exe制作exe文件,但没有运气.

所以现在我正在测试,cx_freeze但它也失败了.

如果有人可以帮助我很多apprecaite

以下是cx_freeze 来自cx_Freeze导入设置,可执行文件的setup.py文件

copyDependentFiles=True
silent = True
includes = ["lxml", "lxml._elementpath", "lxml.etree", "gzip", "encodings.cp949", "encodings.utf_8", "encodings.ascii"]
setup(name='gearfacts',

     options = {
       "build_exe" : {
           "includes": includes,
           },
       },
     executables=[Executable('test.py')],
     ) 
Run Code Online (Sandbox Code Playgroud)

以下是我的脚本源文件.

- - 编码:utf-8 - -

import lxml,cookielib,urllib,configobj,sys,getopt,string,mechanize,time,os 
from lxml import etree
from lxml.html import parse, fromstring
import sys, getopt, string  
import lxml.html
import encodings.utf_8
import encodings.euc_kr 
import encodings.cp949

br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True) …
Run Code Online (Sandbox Code Playgroud)

python cx-freeze

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

标签 统计

python ×4

mechanize ×2

cx-freeze ×1

delphi ×1

text-manipulation ×1