我使用plotly创建了一个表来计算一些财务数据,我想在图形界面中显示整个表(而不仅仅是几行):
正如您在图片中看到的,我的 30 行中只显示了 11 行。我想显示表的所有数据(所有 30 行,没有滚动条)。
该表的代码如下:
fig6 = go.Figure(data=[go.Table(
header=dict(values=list(df_table.columns),
fill_color='#d3d3d3',
align='left'),
cells=dict(values=[df_table['date'],
df_table['P/E_Ratio'],
df_table['Stock Price']],
fill_color='white',
align='left'))
])
Run Code Online (Sandbox Code Playgroud) 当我在 python 中启动 Selenium webdriver.Remote 时,我收到此弃用警告,我的 selenium 版本是selenium==4.0.0b2.post1
desired_capabilities has been deprecated, please pass in an Options object with options kwarg
Run Code Online (Sandbox Code Playgroud)
Option 对象应该是什么?我该如何申报?
这是我的代码:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver
import time
driver = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME
)
driver.get('http://www.google.com/')
Run Code Online (Sandbox Code Playgroud) 我期待使用以下 Tweepy 代码从我的 Twitter 个人资料中提取一些数据:
import tweepy
client = tweepy.Client(consumer_key=consumer_key, consumer_secret=consumer_secret,
access_token=access_token, access_token_secret=access_token_secret)
client.get_tweets(ids=[user_id], tweet_fields=["public_metrics"], expansions=["attachments.media_keys"],
media_fields=["public_metrics"])
Run Code Online (Sandbox Code Playgroud)
问题是,由于某种原因,我收到以下错误:tweepy.errors.Unauthorized: 401 Authorization Required,并且我知道我的凭据有效,因为我成功通过了测试,如下所示:
lookup_users = api.lookup_users(screen_name=screen_name)
Run Code Online (Sandbox Code Playgroud)
这里的问题是我必须授权帐户/应用程序/项目才能获取此数据,但我还没有找到与授予这些授权相关的文档。
我如何授权我的应用程序从帐户获取此信息?
我正在尝试执行quote_count并reply_count使用 Twitter Tweepy API,但我找不到有关如何执行此操作的正确更新文档。
https://developer.twitter.com/en/docs/twitter-api/metrics
我有一些来自 Tweepy 的 Twitter API 版本 1 的工作代码来获取我使用的一些数据,但我找不到有关如何通过 Tweepy 提取reply_count和quote_count使用 Twitter API 版本 2 的良好信息。
import tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, proxy=proxy)
public_tweets = api.user_timeline()
Run Code Online (Sandbox Code Playgroud) 我在 Docker 容器中使用以下 Airflow 版本,目前遇到一些与损坏的 DAG 相关的问题
FROM apache/airflow:2.3.4-python3.9
Run Code Online (Sandbox Code Playgroud)
我有其他 DAG 使用相同的参数“request_cpu”运行并且功能完美,我不确定问题可能是什么
Broken DAG: [/home/airflow/airflow/dags/my_project.py] Traceback (most recent call last):
File "/home/airflow/.local/lib/python3.10/site-packages/airflow/models/baseoperator.py", line 858, in __init__
self.resources = coerce_resources(resources)
File "/home/airflow/.local/lib/python3.10/site-packages/airflow/models/baseoperator.py", line 133, in coerce_resources
return Resources(**resources)
TypeError: Resources.__init__() got an unexpected keyword argument 'request_cpu'
Run Code Online (Sandbox Code Playgroud)
这是我当前的 DAG 配置
# DAG configuration
DAG_ID = "my_project_id"
DAG_DESCRIPTION = "description"
DAG_IMAGE = image
default_args = {
"owner": "airflow",
"depends_on_past": False,
"max_active_tasks": 1,
"max_active_runs": 1,
"email_on_failure": True,
"email": ["my@mail.com"],
"retries": 0,
"email_on_retry": False,
"image_pull_policy": …Run Code Online (Sandbox Code Playgroud) 我有一个巨大的网址列表,其中包含亚马逊产品的链接,该网址包含我需要的信息,称为 ASIN 编号。
我知道提取该信息的最佳方法之一是通过正则表达式,我在网址中发现了一种可以提供帮助的模式
各自的 ASIN 编号为:
1- B07P4LVZNL,位于:dp/B07P4LVZNL/ref=sr_1_f之间
2- B07DXPN7TK,位于:dp/B07DXPN7TK/ref=sr_1_fkmr2_之间
3- B07R23QGH6,位于:gp/B07R23QGH6/ref=sr_1_fkmr2_之间
我尝试了这段代码:
asin = re.match("http[s]?://www.amazon.com(\w+)(.*)/(dp|gp/product)/(?P<asin>\w+).*", href, flags=re.IGNORECASE)
Run Code Online (Sandbox Code Playgroud)
href 是我存储网址的变量
但是好吧......它的效果不太好,这是我得到的结果类型:
<re.Match object; span=(0, 175), match='https://www.amazon.com/adidas-Originals-Solid-Mel>
<re.Match object; span=(0, 171), match='https://www.amazon.com/adidas-Game-Mode-Polo-Mult>
<re.Match object; span=(0, 167), match='https://www.amazon.com/adidas-Tech-Tee-Black-X-La>
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助
我正在尝试将 Twitter API 的版本 2 与 tweepy 3.10.0 一起使用,但在遵循文档https://docs.tweepy.org/en/latest/client.html时我感到困惑
当我尝试设置 API 时,如下例所示:
import tweepy
client = tweepy.Client(consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:属性错误:module 'tweepy' has no attribute 'Client'
我之前使用过 Tweepy,它适用于我配置的一些测试,但我需要使用版本 2,因为我想执行此版本 API 的一些功能。
我的错误是什么?
我尝试在无头模式下通过 selenium 运行 chromedriver。
重要如果我消除以下代码行(但不是无头的),代码运行得非常好:
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
Run Code Online (Sandbox Code Playgroud)
这是我尝试实现无头参数时遇到的错误:
Traceback (most recent call last):
File "camel.py", line 83, in <module>
executable_path=executable_path)
File "/home/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/home/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://jkompbllimaoekaogchhkmkdogpkhojg/_generated_background_page.html
from unknown error: …Run Code Online (Sandbox Code Playgroud) python selenium google-chrome-extension selenium-chromedriver google-chrome-headless
我正在寻找在更少的代码行中使用多个“if”条件的更优雅的替代方案。大多数条件都非常简单,如示例所示:
if status == 'young':
i = 1
elif status == 'middle age':
i = 3
elif status == 'elder':
i = 4
elif status == 'baby':
i = 5
elif status == 'deceased':
i = 6
Run Code Online (Sandbox Code Playgroud)
我想做一些类似的事情:
if status == 'young', 'mid age', 'elder'...
i = 1, 3, 4...
Run Code Online (Sandbox Code Playgroud)
在python中可以吗??
python ×9
tweepy ×3
python-3.x ×2
selenium ×2
twitter ×2
airflow ×1
delete-file ×1
kubernetes ×1
pipenv ×1
plotly ×1
regex ×1
selenium4 ×1
url ×1
web-scraping ×1