python-2.7

Selenium find_elements_by_css_selector returns an empty list

拈花ヽ惹草 提交于 2021-02-07 21:37:48
问题 I'm trying to select all the ids which contain coupon-link keyword with the following script. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://udemycoupon.discountsglobal.com/coupon-category/free-2/") elems = driver.find_elements_by_css_selector('[id~=\"coupon-link\"]') print(elems) But I got an empty list [] as the result. What's wrong with my css_selector? I've tested that find_elements_by_css_selector('[id=\

Selenium find_elements_by_css_selector returns an empty list

守給你的承諾、 提交于 2021-02-07 21:37:13
问题 I'm trying to select all the ids which contain coupon-link keyword with the following script. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://udemycoupon.discountsglobal.com/coupon-category/free-2/") elems = driver.find_elements_by_css_selector('[id~=\"coupon-link\"]') print(elems) But I got an empty list [] as the result. What's wrong with my css_selector? I've tested that find_elements_by_css_selector('[id=\

Import a file from another directory

不羁的心 提交于 2021-02-07 21:11:35
问题 I have a file call entryPoint.py : from .commonLib.deviceLib import * And I have a file called deviceLib.py : import math import sys import logging import requests import this class DeviceLib(object): def __init__(self, connectionDb): self.__db = connectionDb The tree is like this : /test entryPoint.py /commonLib __init__.py deviceLib.py When I execute python entryPoint.py I get the error : Attempted relative import in non-package . Please help me. 回答1: use sys.path.append to append the

Import a file from another directory

核能气质少年 提交于 2021-02-07 21:03:08
问题 I have a file call entryPoint.py : from .commonLib.deviceLib import * And I have a file called deviceLib.py : import math import sys import logging import requests import this class DeviceLib(object): def __init__(self, connectionDb): self.__db = connectionDb The tree is like this : /test entryPoint.py /commonLib __init__.py deviceLib.py When I execute python entryPoint.py I get the error : Attempted relative import in non-package . Please help me. 回答1: use sys.path.append to append the

Python selenium CTRL+C closes chromedriver

北城以北 提交于 2021-02-07 20:27:06
问题 How can I catch CTRL+C (a KeyboardInterrupt) without causing the chromedriver to close. It closes the chromedriver when I run my script.py through cmd. driver = webdriver.Chrome() try: while True: #do stuff with chromedriver except KeyboardInterrupt: print "User pressed CTRL + C" #do other stuff with chromedriver It does catch the KeyboardInterrupt in my script, thus my script continues but the chromedriver also gets it and close itself. EDIT 1: The solution here doesn't work when you run the

How to sort data frame by column values?

僤鯓⒐⒋嵵緔 提交于 2021-02-07 19:50:48
问题 I am relatively new to python and pandas data frames so maybe I have missed something very easy here. So I was having data frame with many rows and columns but at the end finally manage to get only one row with maximum value from each column. I used this code to do that: import pandas as pd d = {'A' : [1.2, 2, 4, 6], 'B' : [2, 8, 10, 12], 'C' : [5, 3, 4, 5], 'D' : [3.5, 9, 1, 11], 'E' : [5, 8, 7.5, 3], 'F' : [8.8, 4, 3, 2]} df = pd.DataFrame(d, index=['a', 'b', 'c', 'd']) print df Out: A B C

How to sort data frame by column values?

天涯浪子 提交于 2021-02-07 19:48:15
问题 I am relatively new to python and pandas data frames so maybe I have missed something very easy here. So I was having data frame with many rows and columns but at the end finally manage to get only one row with maximum value from each column. I used this code to do that: import pandas as pd d = {'A' : [1.2, 2, 4, 6], 'B' : [2, 8, 10, 12], 'C' : [5, 3, 4, 5], 'D' : [3.5, 9, 1, 11], 'E' : [5, 8, 7.5, 3], 'F' : [8.8, 4, 3, 2]} df = pd.DataFrame(d, index=['a', 'b', 'c', 'd']) print df Out: A B C

Python send email with “quoted-printable” transfer-encoding and “utf-8” content-encoding

烈酒焚心 提交于 2021-02-07 19:45:39
问题 python's email.mime tends to use encoding base64 or 7bit and us-ascii . I would like to use quoted-printable and utf-8 as this is easier for humans to read and debug. Currently, my emails look like --===============6135350048414329636== MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: base64 IyEvYmluL2Jhc2gKCmZvciBpIGluIHs4Mjg4Li44N or --===============0756888342500148236== MIME-Version: 1.0 Content-Transfer-Encoding: 7bit happy face =E2=98=BA I would like the raw email

cannot load dll in python with ctypes

孤人 提交于 2021-02-07 18:31:06
问题 I am trying to load a dll form python code with ctypes and it raised an error. my python code: import ctypes from ctypes import * hllDll = ctypes.WinDLL ("c:\\Users\\saar\\Desktop\\pythonTest\\check.dll") and this raised error: Traceback (most recent call last): File "C:\AI\PythonProject\check.py", line 5, in <module> hllDll = ctypes.WinDLL("c:\\Users\\saar\\Desktop\\pythonTest\\check.dll") File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__ self._handle = _dlopen(self._name,

python class factory inherit random parent

久未见 提交于 2021-02-07 14:49:08
问题 I have some code like this: class Person(object): def drive(self, f, t): raise NotImplementedError class John(Person): def drive(self, f, t): print "John drove from %s to %s" % (f,t) class Kyle(Person): def drive(self, f, t): print "Kyle drove from %s to %s" % (f,t) class RandomPerson(Person): # instansiate either John or Kyle, and inherit it. pass class Vehicle(object): pass class Driver(Person, Vehicle): def __init__(self): # instantiate and inherit a RandomPerson somehow pass d1 = Driver()