我正在学习VBA。
我想默默地填写网络表格,例如
Set IE = CreateObject("internet explorer.Application")
IE.VIsible = False
Run Code Online (Sandbox Code Playgroud)
当我用它加载网址时,它说我应该使用另一个浏览器打开它。
我想让它在任何操作系统上兼容。我找到了这个
ActiveWorkbook.FollowLinkAddress "myurl.com"
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将其设置为变量,例如
Set IE = ActiveWorkbook.FollowLinkAddress "myurl.com"
IE.Visible = false
Run Code Online (Sandbox Code Playgroud)
然后我可以做一些事情,比如填写输入字段,单击按钮,......
Set btn = IE.getElementById(...........
btn.Click = true
Run Code Online (Sandbox Code Playgroud)
这是让我头疼的网址:
https://sellercentral.amazon.com/hz/fba/profitabilitycalculator/index?lang=en_US
假设我正在抓取一个网页,并且我想选择网页上的某个图像。正如您可以根据类名称查找元素一样,我想通过其标签来选择图像src。如何选择我已经知道标签的图像src?
即我想选择标签src为:
https://assets.bandsintown.com/images/pin.svg
Run Code Online (Sandbox Code Playgroud) 我正在尝试从包含以下许多 div 的网页中提取内容(显然所有数据都具有不同的数据,除了初始部分):
<div data-asin="B007R2E578" data-index="0"
class="sg-col-20-of-24 s-result-item sg-col-0-of-12 sg-col-28-of-32 sg-col-16-of-20 AdHolder sg-col sg-col-32-of-36 sg-col-12-of-16 sg-col-24-of-28">
<div class="sg-col-inner">
Run Code Online (Sandbox Code Playgroud)
所有这些 div 的开头都相同:<div data-asin=
我正在尝试使用 Beautifulsoup 中的 find_all 函数提取所有这些:
structure = soup.find_all('div','data-asin=')
Run Code Online (Sandbox Code Playgroud)
但是它总是返回一个空列表。
我不想使用正则表达式。
BeautifulSoup中是否有任何函数可以获取所有这些div?
如何通过类名查找元素而不重复输出?我有两堂课要刮hdrlnk和results-price。我写的代码是这样的:
x = driver.find_elements_by_class_name(['hdrlnk','result-price'])
Run Code Online (Sandbox Code Playgroud)
它给了我一些错误。我尝试过另一个代码,如下:
x = driver.find_elements_by_class_name('hdrlnk'),
y = driver.find_elements_by_class_name('result-price')
for xs in x:
for ys in y:
print(xs.text + ys.text)
Run Code Online (Sandbox Code Playgroud)
但我得到了这样的结果
sony 5 disc cd changer$40
sony 5 disc cd changer$70
sony 5 disc cd changer$70
sony 5 disc cd changer$190
sony 5 disc cd changer$190
sony 5 disc cd changer$190
sony 5 disc cd changer$190
sony 5 disc cd changer$10
Run Code Online (Sandbox Code Playgroud)
我试图抓取的 HTML 结构部分
<p class="result-info">
<span class="icon icon-star" role="button" title="save this post in …Run Code Online (Sandbox Code Playgroud) 我正在尝试抓取网站,有时会收到此错误,这令人担忧,因为我随机收到此错误,但在重试后,我没有收到此错误。
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='www.somewebsite.com', port=443): Read timed out. (read timeout=None)
Run Code Online (Sandbox Code Playgroud)
我的代码如下所示
from bs4 import BeautifulSoup
from random_user_agent.user_agent import UserAgent
from random_user_agent.params import SoftwareName, OperatingSystem
import requests
software_names = [SoftwareName.CHROME.value]
operating_systems = [OperatingSystem.WINDOWS.value, OperatingSystem.LINUX.value]
user_agent_rotator = UserAgent(software_names=software_names, operating_systems=operating_systems, limit=100)
pages_to_scrape = ['https://www.somewebsite1.com/page', 'https://www.somewebsite2.com/page242']
for page in pages_to_scrape:
time.sleep(2)
page = requests.get(page, headers={'User-Agent':user_agent_rotator.get_random_user_agent()})
soup = BeautifulSoup(page.content, "html.parser")
# scrape info
Run Code Online (Sandbox Code Playgroud)
正如您从我的代码中看到的,我什至使用 Time 使我的脚本休眠几秒钟,然后再请求另一个页面。我还使用随机的 user_agent。我不确定是否可以做任何其他事情来确保我永远不会收到“读取超时”错误。
我也遇到过这个,但他们似乎建议向标题添加额外的值,但我不确定这是否是一个通用的解决方案,因为这可能必须根据网站的具体情况而定。我还在另一篇SO Post上读到,我们应该对请求进行 Base64 处理并重试。这让我很困惑,因为我不知道该怎么做,而且这个人也没有提供例子。
任何有刮擦经验的人的建议将不胜感激。
我有一个结构如下:
Type Post struct{
ID int64
Title string
Content string
}
Run Code Online (Sandbox Code Playgroud)
我使用Go Colly卷曲一个网页来接收数据,我有两个 OnHtml 方法,如下所示:
func main() {
c := colly.NewCollector()
c.OnHTML("p", func(e *colly.HTMLElement) {
Post := Post{
Content: e.Text
}
db.Create(&Post)
})
c.OnHTML("h", func(e *colly.HTMLElement) {
Post := Post{
Title: e.Text
}
db.Create(&Post)
})
c.Visit("http://go-colly.org/")
}
Run Code Online (Sandbox Code Playgroud)
上面的代码运行良好,但这会在数据库中创建两行,如下所示:
+--------------+---------------+---------------+
| id | title | content |
+--------------+---------------+---------------+
| 1 | Hello | Null |
+--------------+---------------+---------------+
| 2 | Null | Mycontent ... |
+--------------+---------------+---------------+
Run Code Online (Sandbox Code Playgroud)
我想创建它:
+--------------+---------------+---------------+
| id | …Run Code Online (Sandbox Code Playgroud) 我看到有一些关于此的帖子,但每种情况显然都是独一无二的。我试图获取此页面图表背后的数据: https ://www.tradingview.com/symbols/NASDAQ-VOLI/
这是一个相当模糊的市场指数,并且无法通过雅虎获得,这是我通常查看的地方(特别web.DataReader是在Python中),并且这是似乎拥有全套每日价格的少数几个网站之一。
<script nonce="XL1oARYPz8X2tvqk">
window.__defaultsOverrides = {
'mainSeriesProperties.style': 3,
'mainSeriesProperties.areaStyle.priceSource': 'close',
'scalesProperties.lineColor': 'rgba( 76, 82, 94, 1)',
'scalesProperties.showSymbolLabels': false,
'scalesProperties.textColor': 'rgba( 76, 82, 94, 1)',
'scalesProperties.seriesLastValueMode': 0,
'paneProperties.topMargin': 13,
'paneProperties.legendProperties.showStudyArguments': false,
'paneProperties.legendProperties.showStudyTitles': false,
'paneProperties.legendProperties.showStudyValues': false,
'paneProperties.legendProperties.showSeriesTitle': false,
'paneProperties.legendProperties.showSeriesOHLC': true,
'paneProperties.legendProperties.showLegend': false,
};
</script>
Run Code Online (Sandbox Code Playgroud)
这就是与图表相关的元素,坦率地说,它在 Web 开发方面有点超出我的理解,因为它只是一个脚本标签(即,它不仅仅是图表元素的子元素 - 它是图表元素)。我尝试在 JS 文件中搜索 的随机数值XL1oARYPz8X2tvqk,但没有看到任何看起来会填充图表的内容。
我认为我能够在窗口对象中的某个位置找到图表数据,但我没有看到它。有没有一种简单的方法可以追踪到这一点?我知道我可以使用交互式刮刀,但看起来它必须比这更容易。
我正在尝试从“https://www.metabolomicsworkbench.org/data/mb_struct_ajax.php”中抓取表格。
我在网上找到的代码(rvest)不起作用
library(rvest)
url <- "https://www.metabolomicsworkbench.org/data/mb_structure_ajax.php"
A <- url %>%
read_html() %>%
html_nodes(xpath='//*[@id="containerx"]/div[1]/table') %>%
html_table()
Run Code Online (Sandbox Code Playgroud)
A 是“0 的列表”
我应该如何修复此代码或者有更好的方法吗?
提前致谢。
我正在按照以下教程将股票期权数据导入 Google 工作表。
https://www.youtube.com/watch?v=Be7z9YeeVY0&ab_channel=daneshj
以下公式将把雅虎财经的数据导入到工作表中:
=iferror(TRANSPOSE(IMPORTXML(CONCATENATE("https://finance.yahoo.com/quote/",A2,"?p=",A2),"//tr")),"You have to add a contract name in column A")
Run Code Online (Sandbox Code Playgroud)
乍一看,一切看起来都很好,因为它似乎是从网页上拉回数据;然而,所有的值都是不正确的。
本示例中从中提取数据的 URL 如下。请注意,数据经常变化。
https://finance.yahoo.com/quote/NKLA220121C00002500?p=NKLA220121C00002500
这些数字不仅在这个特定示例中是错误的,而且每次都是错误的,并且误差范围足够大,我不认为这是由于 IMPORTXML 缓存页面造成的。我已经搜索了网页的 HTML 源代码,但在任何地方都找不到 IMPORTXML 中的值。
google-sheets web-scraping google-apps-script yahoo-finance google-sheets-formula
我在从 devoloper 工具的控制台日志中已存在的站点获取数据时遇到问题。我是 Puppeteer 的新手,所以我试图获取所有这些控制台日志结果,但它们都有字符串类型。你们能帮我找到一种方法来获取真实的对象或者一种解析它并使用它的方法吗,谢谢
web-scraping ×10
python ×5
html ×2
javascript ×2
automation ×1
css ×1
excel ×1
go ×1
node.js ×1
puppeteer ×1
python-3.x ×1
r ×1
rvest ×1
scrape ×1
submit ×1
vba ×1
webforms ×1
xpath ×1