我有这个代理地址: 125.119.175.48:8909
如何使用cURL执行HTTP请求curl http://www.example.com,但是指定网络的代理地址?
可能重复:
在创建它们的函数之外的函数中使用全局变量
我有以下脚本:
COUNT = 0
def increment():
COUNT = COUNT+1
increment()
print COUNT
Run Code Online (Sandbox Code Playgroud)
我只想增加全局变量COUNT,但是这给了我以下错误:
Traceback (most recent call last):
File "test.py", line 6, in <module>
increment()
File "test.py", line 4, in increment
COUNT = COUNT+1
UnboundLocalError: local variable 'COUNT' referenced before assignment
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我有以下脚本:
import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
import urllib2
print(urllib2.urlopen("http://www.ifconfig.me/ip").read())
Run Code Online (Sandbox Code Playgroud)
使用tor和SocksiPy
现在我想为每个请求更改tor身份,例如:
for i in range(0, 10):
#somehow change tor identity
print(urllib2.urlopen("http://www.ifconfig.me/ip").read())
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
其中一个算法竞赛网站存在很大问题.我试图解决它5天.我不是要求你为我解决这个问题,因为我是算法的新手,我想请你帮我解决这类问题的分类,有没有人解决过这样的问题,NP问题的类型是什么.请不要以为我要求你为我解决这个问题,我的目的只是学习算法,这对我来说是个问题:
这个难题的目标是确定在哪里放置一组加油站,使它们最接近机场.机场利用大量天然气为飞机提供燃料,因此将加油站靠近它们具有重要战略意义.
输入规范您的程序应该只使用一个命令行参数:输入文件(传递argv,args,参数取决于语言).输入文件的格式如下:
第一行包含一个整数:n机场数n个后续行每个包含2个浮点值xi yi表示第i个机场的坐标,下一行包含要分析的案例数p(p总是小于5)以下p行每行包含一个整数gi,给出所需加油站的数量
输出规格:您的程序应将结果输出到标准输出(printf,print,echo,write):您的输出应包含p行,每行提供加油站的gj坐标xj,yj.您的解决方案得分将根据解决方案的质量来衡量.解决方案的质量由总距离测量,总距离D是从每个机场到其最近的加油站的平方距离之和的平方根.总距离D越低,得分越高.
我是lxml的新手.我想下载网页并从中获取感兴趣的数据,我的代码是:
import urllib2
from lxml import etree
url = "http://www.example.com/"
html = urllib2.urlopen(url)
root = etree.parse(html) # the problem is here
Run Code Online (Sandbox Code Playgroud)
有谁能解释我为什么这是错的?
错误是:
Traceback (most recent call last):
File "yatego.py", line 10, in <module>
root = etree.parse(html)
File "lxml.etree.pyx", line 2942, in lxml.etree.parse (src/lxml/lxml.etree.c:54187)
File "parser.pxi", line 1550, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:79703)
File "parser.pxi", line 1580, in lxml.etree._parseFilelikeDocument (src/lxml/lxml.etree.c:80012)
File "parser.pxi", line 1463, in lxml.etree._parseDocFromFilelike (src/lxml/lxml.etree.c:78908)
File "parser.pxi", line 1019, in lxml.etree._BaseParser._parseDocFromFilelike (src/lxml/lxml.etree.c:75905)
File "parser.pxi", line 564, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:71739)
File …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
import sqlite3
con = sqlite3.connect("testDB")
cur = con.cursor()
#cur.execute('CREATE TABLE test_table (id integer primary key, data text)')
cur.execute('INSERT INTO test_table VALUES (?, ?)', (76, 'MyData'))
Run Code Online (Sandbox Code Playgroud)
当我运行此脚本时,它不会更新表.但是当我在Linux中使用sqlite3命令行进行相同的插入时,它会更新.为什么这样或有什么我做错了?
我有以下脚本使用SocksiPY
和Tor:
from TorCtl import TorCtl
import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
import urllib2
import sqlite3
from BeautifulSoup import BeautifulSoup
def newId():
conn = TorCtl.connect(controlAddr="127.0.0.1", controlPort=9051, passphrase="123")
TorCtl.Connection.send_signal(conn, "NEWNYM")
newId()
print(urllib2.urlopen("http://www.ifconfig.me/ip").read())
Run Code Online (Sandbox Code Playgroud)
此代码应更改Tor标识,但它会等待一段时间并发出以下错误:
tuple index out of range
Traceback (most recent call last):
File "template.py", line 16, in <module>
newId()
File "template.py", line 14, in newId
TorCtl.Connection.send_signal(conn, "NEWNYM")
TypeError: unbound method send_signal() must be called with Connection instance as first argument (got NoneType instance instead)
Run Code Online (Sandbox Code Playgroud)
但上面的脚本分为两个独立的脚本: …
你好!我在连接到远程主机时遇到问题。我忘记了 ssh 密码,但我有 SSH 密钥的指纹。是否可以仅使用指纹进行连接?
你好开发者!我正在学习Skiena的算法设计手册中的算法.我有以下代码:
#include <stdio.h>
#include <stdlib.h>
typedef int item_type;
typedef struct{
item_type item;
struct list* next;
}list;
void insert_list(list **l, item_type x){
list *p;
p = malloc(sizeof(list));
p->item = x;
p->next = *l;
*l = p;
}
int main(){
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它在编译时给我警告:
gcc -Wall -o"test""test.c"(在目录中:/ home/akacoder/Desktop/Algorithm_Design_Manual/chapter2)test.c:在函数'insert_list'中:test.c:15:警告:从不兼容的指针赋值类型编译成功完成.
但是,当我将此代码重写为C++时:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef int item_type;
typedef struct{
item_type item;
struct list* next;
}list;
void insert_list(list **l, item_type x){
list *p;
p = malloc(sizeof(list));
p->item = x; …Run Code Online (Sandbox Code Playgroud) 嗨,大家好!我有以下代码:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define MAXN 301
string names[MAXN];
vector<string> names_vec;
int main(int argc, char **argv)
{
ifstream fin(argv[1]);
int n;
fin>>n;
string line;
while(getline(fin, line))
names_vec.push_back(line);
for(int i=0; i<names_vec.size(); i++)
cout<<names_vec[i]<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
和names.in文件输入:
5
CLEOpatra
AISHWARYA rai
jOHn f. KeNNeDy
leonardo DA Vinci
tyleR durdeN
Run Code Online (Sandbox Code Playgroud)
当我编译并运行它时,首先打印空行,name_vec [0]为空行.任何人都可以解释为什么以及如何解决它?
我需要安装WebScarab但我不知道git是什么以及如何使用git安装它.任何人都可以解释我,如何从Git安装最新的WebScarab.链接:http://dawes.za.net/gitweb.cgi
我正在编写python脚本,从网站获取链接.但是当我尝试使用这个网页时,我无法获得链接.我的脚本是:
soup = BeautifulSoup(urllib2.urlopen(url))
datas = soup.findAll('div', attrs={'class':'tsrImg'})
for data in datas:
link = data.find('a')
print str(link.href)
Run Code Online (Sandbox Code Playgroud)
它只打印无,任何人都可以解释为什么会这样???
大家好!我想通过python脚本访问一些网页.网址是:http://www.idealo.de/preisvergleich/Shop/27039.html
当我通过网络浏览器访问它时,没关系.但是当我想用urllib2访问它时:
a = urllib2.urlopen("http://www.idealo.de/preisvergleich/Shop/27039.html")
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 406, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 444, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, …Run Code Online (Sandbox Code Playgroud)