小编Car*_*to_的帖子

Urllib2和BeautifulSoup:好夫妻但是太慢了 - urllib3&threads?

当我听到有关线程和urllib3的一些好消息时,我正在寻找一种优化代码的方法.显然,人们不同意哪种解决方案是最好的.

下面我的脚本的问题是执行时间:太慢了!

第1步:我获取此页面 http://www.cambridgeesol.org/institutions/results.php?region=Afghanistan&type=&BULATS=on

第2步:我使用BeautifulSoup解析页面

第3步:我将数据放在excel doc中

第4步:我再次,我的名单中的所有国家(大名单)再次这样做(我只是将网址中的"阿富汗"改为另一个国家)

这是我的代码:

ws = wb.add_sheet("BULATS_IA") #We add a new tab in the excel doc
    x = 0 # We need x and y for pulling the data into the excel doc
    y = 0
    Countries_List = ['Afghanistan','Albania','Andorra','Argentina','Armenia','Australia','Austria','Azerbaijan','Bahrain','Bangladesh','Belgium','Belize','Bolivia','Bosnia and Herzegovina','Brazil','Brunei Darussalam','Bulgaria','Cameroon','Canada','Central African Republic','Chile','China','Colombia','Costa Rica','Croatia','Cuba','Cyprus','Czech Republic','Denmark','Dominican Republic','Ecuador','Egypt','Eritrea','Estonia','Ethiopia','Faroe Islands','Fiji','Finland','France','French Polynesia','Georgia','Germany','Gibraltar','Greece','Grenada','Hong Kong','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Israel','Italy','Jamaica','Japan','Jordan','Kazakhstan','Kenya','Kuwait','Latvia','Lebanon','Libya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Malaysia','Maldives','Malta','Mexico','Monaco','Montenegro','Morocco','Mozambique','Myanmar (Burma)','Nepal','Netherlands','New Caledonia','New Zealand','Nigeria','Norway','Oman','Pakistan','Palestine','Papua New Guinea','Paraguay','Peru','Philippines','Poland','Portugal','Qatar','Romania','Russia','Saudi Arabia','Serbia','Singapore','Slovakia','Slovenia','South Africa','South Korea','Spain','Sri Lanka','Sweden','Switzerland','Syria','Taiwan','Thailand','Trinadad and Tobago','Tunisia','Turkey','Ukraine','United Arab Emirates','United Kingdom','United States','Uruguay','Uzbekistan','Venezuela','Vietnam']
    Longueur = len(Countries_List)



    for Countries in …
Run Code Online (Sandbox Code Playgroud)

python performance multithreading urllib2 beautifulsoup

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

像OS X上的pyHook之类的东西

我实际上正在使用pyHook,但我也想为OS X编写程序.如果有人知道这样的模块......我已经在网上看了一段时间,但没有什么真正相关的.

- >想法是能够在python应用程序之外记录击键.我的应用程序是社区统计信息构建器,因此从OS X获取统计信息也很棒.

提前致谢 ;)

编辑:PyHook:在python应用程序之外记录击键和其他内容 http://sourceforge.net/apps/mediawiki/pyhook/index.php?title=PyHook_Tutorial http://pyhook.sourceforge.net/doc_1.5.0/ http: //sourceforge.net/apps/mediawiki/pyhook/index.php?title=Main_Page

python macos keylogger pyhook

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

Python捕获OS X上的文本文件中的击键值

我正在尝试监视Macbook上的击键,以便构建统计分析器.但是我怎样才能将这些字符与"事件"隔离开来,这更像是:

NSEvent:type = KeyDown loc =(850,248)time = 66551.8 flags = 0x100 win = 0x0 winNum = 0 ctxt = 0x0 chars ="l"unmodchars ="l"repeat = 0 keyCode = 37

所以有人知道如何根据下面发布的脚本,使用chars(来自NSEvent)的值来实现一个.txt doc吗?我需要一个带有按键的文本文件,以便在其上运行我的其他脚本并分析频率等...

提前致谢 ;)

#!/usr/bin/python
# -*- coding: utf-8 -*-


from AppKit import NSApplication, NSApp
from Foundation import NSObject, NSLog
from Cocoa import NSEvent, NSKeyDownMask
from PyObjCTools import AppHelper

class AppDelegate(NSObject):
    def applicationDidFinishLaunching_(self, notification):
        mask = NSKeyDownMask
        NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(mask, handler)

def handler(event):
    try:
        print event
    except KeyboardInterrupt:
        AppHelper.stopEventLoop()

def main():
    app = NSApplication.sharedApplication() …
Run Code Online (Sandbox Code Playgroud)

python macos pyobjc

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

Pythonic方法比较两个CSV文件以跟踪更改

我有一个生成CSV的Python脚本(从网站解析的数据).以下是CSV文件的示例:

File1.csv

China;Beijing;Auralog Software Development (Deijing) Co. Ltd.;;;
United Kingdom;Oxford;Azad University (Ir) In Oxford Ltd;;;
Italy;Bari;Bari, The British School;;Yes;
China;Beijing;Beijing Foreign Enterprise Service Group Co Ltd;;;
China;Beijing;Beijing Ying Biao Human Resources Development Limited;;Yes;
China;Beijing;BeiwaiOnline BFSU;;;
Italy;Curno;Bergamo, Anderson House;;Yes;
Run Code Online (Sandbox Code Playgroud)

File2.csv

China;Beijing;Auralog Software Development (Deijing) Co. Ltd.;;;
United Kingdom;Oxford;Azad University (Ir) In Oxford Ltd;;;
Italy;Bari;Bari, The British School;;Yes;
China;Beijing;Beijing Foreign Enterprise Service Group Co Ltd;;;
China;Beijing;Beijing Ying Biao Human Resources Development Limited;;Yes;
This;Is;A;New;Line;;
Italy;Curno;Bergamo, Anderson House;;Yes;
Run Code Online (Sandbox Code Playgroud)

如你看到的,

中国;北京;北外在线BFSU ;;; ==>来自File1.csv的这一行在File2.csv和This; Is; …

python csv comparison

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

MysQl错误:参数号无效

我收到此错误:

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /FondManager.class.php on line 69
Run Code Online (Sandbox Code Playgroud)

尝试执行此操作时:

$Fond_Modif = $Manager->get($id);
$Fond_Modif->setContactname($_POST['name']);
$Manager->update($Fond_Modif);
Run Code Online (Sandbox Code Playgroud)

这是关注的课程:

 public function update(Fond $Fond)
  {
    $q = $this->_db->prepare('UPDATE fonds SET Name, ContactName, ContactPosition, ContactMail, ContactPhone, Website, MinTic, MaxTic WHERE id = :id');

    $q->bindValue(':id', $Fond->id());
    $q->bindValue(':name', $Fond->name(), PDO::PARAM_INT);
    $q->bindValue(':contactname', $Fond->contactname(), PDO::PARAM_INT);
    $q->bindValue(':contactposition', $Fond->contactposition(), PDO::PARAM_INT);
    $q->bindValue(':contactmail', $Fond->contactmail(), PDO::PARAM_INT);
    $q->bindValue(':contactphone', $Fond->contactphone(), PDO::PARAM_INT);
    $q->bindValue(':website', $Fond->website(), PDO::PARAM_INT);
    $q->bindValue(':mintic', $Fond->mintic(), PDO::PARAM_INT);
    $q->bindValue(':maxtic', $Fond->maxtic(), PDO::PARAM_INT);

    $q->execute();
  }
Run Code Online (Sandbox Code Playgroud)

php mysql

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