我仍然在学习并回答我的一个问题:在这里,我被告知它可能是因为有问题的元素不在视野中.
我查看了文档,所以这里是最相关的答案:这里
您可以使用"org.openqa.selenium.interactions.Actions"类移动到元素:
WebElement element = driver.findElement(By.id("my-id"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
## actions.click();
actions.perform();
Run Code Online (Sandbox Code Playgroud)
当我尝试使用上面的内容滚动到元素时:它说WebElement没有定义.
我想这是因为我没有导入相关模块.有人可以指出我应该导入的内容吗?
编辑:正如alecxe所指出的,这是java代码.
但与此同时,在试图弄清楚它一段时间之后.我找到了WebElement的导入方法:
from selenium.webdriver.remote.webelement import WebElement
Run Code Online (Sandbox Code Playgroud)
可能会帮助像我这样的人.
如何,这也是一个很好的教训,IMO:
去:文档 的
class selenium.webdriver.remote.webelement.WebElement(parent, id_, w3c=False)
Run Code Online (Sandbox Code Playgroud)
需要分成上面提到的命令格式.
我对统计和编程很陌生。我已经自学了一些,但我很难理解p-value
adfuller 测试的概念和其他各种结果。
我正在使用的代码:
(我在 stockoverflow 上找到了这段代码)
import numpy as np
import os
import pandas as pd
import statsmodels.api as sm
import cython
import statsmodels.tsa.stattools as ts
loc = r"C:\Stock Study\Stock Research\Hist Data"
os.chdir(loc)
xl_file1 = pd.ExcelFile("HDFCBANK.xlsx")
xl_file2 = pd.ExcelFile("KOTAKBANK.xlsx")
y1 = xl_file1.parse("Sheet1")
x1 = xl_file2.parse("Sheet1")
x = x1['Close']
y = y1['Close']
def cointegration_test(y, x):
# Step 1: regress on variable on the other
ols_result = sm.OLS(y, x).fit()
# Step 2: obtain the residual (ols_resuld.resid)
# Step 3: apply …
Run Code Online (Sandbox Code Playgroud) 它之前工作得很好,但由于某种原因,现在我遇到了奇怪的错误。
熊猫版本:1.2.3
matplotlib 版本:3.7.0
示例数据框:
df
cap Date
0 1 2022-01-04
1 2 2022-01-06
2 3 2022-01-07
3 4 2022-01-08
Run Code Online (Sandbox Code Playgroud)
df.plot(x='cap', y='Date')
plt.show()
Run Code Online (Sandbox Code Playgroud)
df.dtypes
cap int64
Date datetime64[ns]
dtype: object
Run Code Online (Sandbox Code Playgroud)
我得到一个回溯:
df
cap Date
0 1 2022-01-04
1 2 2022-01-06
2 3 2022-01-07
3 4 2022-01-08
Run Code Online (Sandbox Code Playgroud) 我试图从 Pandas 的列中减去今天的日期以获得天数(作为整数)。
我首先使用pd.to_datetime
.
df['Date'] - datetime.datetime.now().date()
我收到以下错误:
类型错误:不支持的操作数类型 -:'DatetimeIndex' 和 'datetime.date'
我想弄清楚如何让它工作,还将天数转换为整数?
我是使用requests
和的完全新手tor
。
我正在使用的代码:
def get_tor_session():
session = requests.session()
# Tor uses the 9050 port as the default socks port
session.proxies = {'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}
return session
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
Run Code Online (Sandbox Code Playgroud)
我不断收到以下错误:
raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: SOCKSHTTPConnectionPool(host='httpbin.org', port=80): url 超出最大重试次数:/ip (由 NewConnectionError(': 无法建立新连接引起)连接:[WinError 10061]无法建立连接,因为目标机器主动拒绝它',))
我查看了各种答案,但无法找出问题所在。
我刚刚从 Ubuntu 跳到了 MacBook Air M1。
我正在尝试以一种不必更改两者脚本的方式设置系统。即我想以这样的方式保留脚本,以便在任一系统上进行编辑都可以。
在脚本中我使用以下代码行:
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
Run Code Online (Sandbox Code Playgroud)
我使用 Homebrew 进行安装chromium-browser
,但找不到该文件(所以我可以将其移至此位置?)。
我已经尝试了几乎所有我能查到的东西,但无法弄清楚。接下来我可以尝试什么?
Ubuntu 18.x + selenium webdriver(Firefox)
面对一个奇怪的问题,如果我run
将它们全部放在一起,下面的块就可以工作了
from selenium import webdriver
url = 'https://indiamart.com'
driver = webdriver.Firefox()
driver.get(url)
driver.find_element_by_xpath(xpath).click()
Run Code Online (Sandbox Code Playgroud)
每次url
尝试过都会发生这种情况.
但是,如果我一次执行一行,它会给出
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 326, in get
self.execute(Command.GET, {'url': url})
File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
response = self.command_executor.execute(driver_command, params)
File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute
return self._request(command_info[0], url, body=data)
File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 495, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "/usr/lib/python3.6/http/client.py", line 1239, in request …
Run Code Online (Sandbox Code Playgroud) 我打开了一个网页,并使用webdriver代码登录.使用webdriver是因为在我设置为scrape之前页面需要登录和各种其他操作.
目的是从这个打开的页面中抓取数据.需要找到链接并打开它们,因此selenium webdriver和BeautifulSoup之间会有很多组合.
我查看了bs4的文档,并BeautifulSoup(open("ccc.html"))
抛出了一个错误
soup = bs4.BeautifulSoup(open("https://m/search.mp?ss=Pr+Dn+Ts"))
OSError:[Errno 22]参数无效:' https://m/search.mp?ss = Pr + Dn + Ts '
我认为这是因为它不是.html
?
我想添加codes
到dataframe dictionary
.
codes = [['01', '02', '03', '05', '06', '08', '10', '11', '13', '15', '17', '19', '21', '23', '25', '27', '29', '31', '33', '35', '37', '39', '43', '45', '4.55', '48', '52']
#27Codes
df = pd.read_excel(sales,sheet_name=None,ignore_index = True, skiprows=7)
#27 Sheets
for i in codes:
for key in df.keys():
df['Sheet1']['Code'] = i
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么我似乎i
在每个数据帧中都有.我想我理解为什么我无法弄清楚如何纠正它.
我是编码的新手,我根本无法找到解决方案.
预期产量:
df['Sheet1']
Date Particulars Inwards Code
1 2017-04-01 EFG 12800 01
2 2017-07-22 ABC 100 01
3 2017-09-05 BCD 10000 01 …
Run Code Online (Sandbox Code Playgroud) 我已阅读答案,但无法解释此表达式是否有效:
*/5 930-1530 * * 1-5 <command>
Run Code Online (Sandbox Code Playgroud)
我试图在工作日的上午 9:15 到下午 15:30 之间每 5 分钟运行一次脚本
新的cron
和ubuntu
提前致谢。
python ×6
selenium ×4
pandas ×3
python-3.x ×2
ubuntu ×2
cron ×1
dataframe ×1
dictionary ×1
macos ×1
math ×1
matplotlib ×1
statistics ×1
statsmodels ×1
tor ×1