我正在尝试使用PyInstaller创建一个独立的OSX应用程序,它运行我已经制作的GUI.当我在终端中输入以下内容时:
pyinstaller gui.py
Run Code Online (Sandbox Code Playgroud)
一切似乎都有效,直到我收到以下错误:
File "/Users/username/anaconda/bin/PyInstaller", line 11, in <module>
sys.exit(run())
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'),
kw.get('clean_build'))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 734, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 212, in __init__
self.__postinit__()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/datastruct.py", line 178, in __postinit__
self.assemble()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 470, in assemble …
Run Code Online (Sandbox Code Playgroud) 我创建了以下数据帧 df
col1 col2 col3
0 4 5 2
1 5 2 4
2 3 10 3
3 6 2 2
4 3 2 4
Run Code Online (Sandbox Code Playgroud)
我现在想要的是翻转行,以便df看起来像这样:
column_name value
0 col1 4
1 col2 5
2 col3 2
3 col1 5
4 col2 2
5 col3 4
... ... ...
Run Code Online (Sandbox Code Playgroud)
我想我需要使用stack(),但我不确定如何.我尝试了以下内容
df = df.stack().rename_axis(['column_name']).reset_index(name = 'value')
Run Code Online (Sandbox Code Playgroud)
但是会返回以下错误
raise ValueError('Length of names must match number of levels in '
ValueError: Length of names must match number of levels in MultiIndex. …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Excel 中的搜索公式来检查列是否包含字符串。但是,我不需要精确的匹配。所以 fi,如果列中的单元格中有 abcd,并且当我搜索 abc 时,我仍然想要返回一个值。不幸的是,目前我只有在精确搜索 abcd 时才会得到返回值。
我现在使用的公式如下所示:
=SEARCH("abc";A2:A8)
Run Code Online (Sandbox Code Playgroud)
即使 A3 中有“abcd”,也没有返回任何值。
提前致谢!
我正在尝试浏览名为 iens 的网站上的不同页面。我正在使用 selenium + python 单击“volgende”(在荷兰语中表示“下一个”),但我希望我的程序继续单击下一个,直到使用 while 循环没有更多页面为止。所以在这种情况下,我希望我的程序在第 23 页结束。现在我可以通过关闭 cookie 弹出消息进入第 2 页,等到它关闭然后单击“Volgende”按钮。
我的代码如下所示:
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
chrome_path = '/Users/user/Downloads/chromedriver'
driver = webdriver.Chrome(chrome_path)
driver.get('https://www.iens.nl/restaurant+utrecht')
#wait for cookie message
close_icon = WebDriverWait(driver, 5,
0.25).until(EC.visibility_of_element_located([By.CSS_SELECTOR,
'.cookiePolicy-close']))
close_icon.click()
#wait for cookie message to disappear
WebDriverWait(driver, 5,
0.25).until(EC.invisibility_of_element_located([By.CSS_SELECTOR,
'.cookiePolicy-close']))
click_icon = WebDriverWait(driver, 5,
0.25).until(EC.visibility_of_element_located([By.LINK_TEXT,
'Volgende']))
click_icon.click()
Run Code Online (Sandbox Code Playgroud)
该网站名为https://www.iens.nl/restaurant+utrecht
提前致谢!
我正在尝试使用QT Designer创建GUI.我使用以下教程将我的.ui设计器文件转换为.py文件:http://pyqt.sourceforge.net/Docs/PyQt5/designer.html.
我有以下代码:
#
# Created by: PyQt5 UI code generator 5.7
#
# WARNING! All changes made in this file will be lost!
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QDialog
class Ui_ImageDialog(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(160, 200, 191, 151))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(450, 200, 191, 151))
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(150, 70, 501, 101))
palette = QtGui.QPalette()
brush …
Run Code Online (Sandbox Code Playgroud) 我正在学习如何使用scrapy.作为练习,我正在尝试访问https://www.ubereats.com/stores/,单击地址文本框,输入位置,然后按Enter按钮移动到包含可用于此的餐馆的下一页地点.我有以下lua代码:
function main(splash)
local url = splash.args.url
assert(splash:go(url))
assert(splash:wait(5))
local element = splash:select('.base_29SQWm')
local bounds = element:bounds()
assert(element:mouseclick{x = bounds.width/2, y = bounds.height/2})
assert(element:send_text("Wall Street"))
assert(splash:send_keys("<Return>"))
assert(splash:wait(5))
return {
html = splash:html(),
}
end
Run Code Online (Sandbox Code Playgroud)
当我点击"渲染!" 在splash API中,我收到以下错误消息:
{
"info": {
"message": "Lua error: [string \"function main(splash)\r...\"]:7: attempt to index local 'element' (a nil value)",
"type": "LUA_ERROR",
"error": "attempt to index local 'element' (a nil value)",
"source": "[string \"function main(splash)\r...\"]",
"line_number": 7
},
"error": 400,
"type": "ScriptError",
"description": "Error …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将scrapy与selenium一起使用,以便能够与javascript交互,并且仍然拥有scrapy提供的强大的抓取框架。我编写了一个访问http://www.iens.nl的脚本,在搜索栏中输入“阿姆斯特丹”,然后成功点击搜索按钮。单击搜索按钮后,我希望scrapy 从新呈现的页面中检索一个元素。不幸的是,scrapy 不返回任何值。
这是我的代码的样子:
from selenium import webdriver
from scrapy.loader import ItemLoader
from scrapy import Request
from scrapy.crawler import CrawlerProcess
from properties import PropertiesItem
import scrapy
class BasicSpider(scrapy.Spider):
name = "basic"
allowed_domains = ["web"]
# Start on a property page
start_urls = ['http://www.iens.nl']
def __init__(self):
chrome_path = '/Users/username/Documents/chromedriver'
self.driver = webdriver.Chrome(chrome_path)
def parse(self, response):
self.driver.get(response.url)
text_box = self.driver.find_element_by_xpath('//*[@id="searchText"]')
submit_button = self.driver.find_element_by_xpath('//*[@id="button_search"]')
text_box.send_keys("Amsterdam")
submit_button.click()
l = ItemLoader(item=PropertiesItem(), response=response)
l.add_xpath('description', '//*[@id="results"]/ul/li[1]/div[2]/h3/a/')
return l.load_item()
process = CrawlerProcess()
process.crawl(BasicSpider)
process.start()
Run Code Online (Sandbox Code Playgroud)
“properties”是另一个脚本,看起来像这样:
from …
Run Code Online (Sandbox Code Playgroud) 我想弄清楚scrapy和泼水.作为练习,我尝试在下面的javascript网站上点击按钮:http://thestlbrowns.com/然后返回新渲染页面的html.
我的代码看起来像这样:
import scrapy
import json
from scrapy import Request
class MySpider(scrapy.Spider):
name = 'spiderman'
domain = ['web']
start_urls = ['http://thestlbrowns.com/']
def start_requests(self):
script = """
function main(splash)
local url = splash.args.url
assert(splash:go(url))
assert(splash:wait(1))
assert(splash:runjs("$('#title.play-ball > a:first-child').click()"))
assert(splash:wait(1))
-- return result as a JSON object
return {
html = splash:html(),
-- we don't need screenshot or network activity
--png = splash:png(),
--har = splash:har(),
}
end
"""
for url in self.start_urls:
yield Request(url, self.parse, meta={'splash': {'args':{'lua_source': …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个lua脚本,该脚本要与scrapy + splash一起用于网站。我想编写一个输入文本然后单击一个按钮的脚本。我有以下代码:
function main(splash)
local url = splash.args.url
assert(splash:go(url))
assert(splash:wait(5))
local element = splash:select('.input_29SQWm')
assert(element:send_text("Wall Street, New York"))
assert(splash:send_keys("<Return>"))
assert(splash:wait(5))
return {
html = splash:html(),
}
end
Run Code Online (Sandbox Code Playgroud)
现在,我正在使用启动API来测试我的代码是否正常运行。当我单击“渲染!”时 我收到以下消息:
{
"info": {
"message": "Lua error: [string \"function main(splash)\r...\"]:7: attempt to index local 'element' (a nil value)",
"type": "LUA_ERROR",
"error": "attempt to index local 'element' (a nil value)",
"source": "[string \"function main(splash)\r...\"]",
"line_number": 7
},
"error": 400,
"type": "ScriptError",
"description": "Error happened while executing Lua script"
}
Run Code Online (Sandbox Code Playgroud)
因此,由于某些原因,当我尝试发送“纽约华尔街”时,元素仍然为零。我不明白为什么;如果我在Chrome控制台中输入以下内容:
$('.input_29SQWm')
Run Code Online (Sandbox Code Playgroud)
我找到了想要的元素! …
我正在学习如何使用scrapy + splash.我已经在虚拟环境中创建了一个项目,现在我正在做这个教程:https://github.com/scrapy-plugins/scrapy-splash.
我跑过了:
$ docker run -p 8050:8050 scrapinghub/splash
Run Code Online (Sandbox Code Playgroud)
结果导致:
2017-01-12 09:18:50+0000 [-] Log opened.
2017-01-12 09:18:50.225754 [-] Splash version: 2.3
2017-01-12 09:18:50.227033 [-] Qt 5.5.1, PyQt 5.5.1, WebKit 538.1, sip 4.17, Twisted 16.1.1, Lua 5.2
2017-01-12 09:18:50.227201 [-] Python 3.4.3 (default, Nov 17 2016, 01:08:31) [GCC 4.8.4]
2017-01-12 09:18:50.227645 [-] Open files limit: 1048576
2017-01-12 09:18:50.227882 [-] Can't bump open files limit
2017-01-12 09:18:50.333978 [-] Xvfb is started: ['Xvfb', ':1', '-screen', '0', '1024x768x24']
2017-01-12 …
Run Code Online (Sandbox Code Playgroud) python ×7
javascript ×5
scrapy ×5
web-scraping ×3
lua ×2
selenium ×2
cookies ×1
dataframe ×1
excel ×1
macos ×1
pandas ×1
pyinstaller ×1
pyqt ×1
pyqt5 ×1
python-3.x ×1
qt ×1
qt-designer ×1
terminal ×1