相关疑难解决方法(0)

使用Python在Selenium WebDriver中获取WebElement的HTML源代码

我正在使用Python绑定来运行Selenium WebDriver.

from selenium import webdriver
wd = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)

我知道我可以抓住这样的一个元素......

elem = wd.find_element_by_css_selector('#my-id')
Run Code Online (Sandbox Code Playgroud)

而且我知道我可以获得完整的页面来源...

wd.page_source
Run Code Online (Sandbox Code Playgroud)

但无论如何要获得"元素来源"?

elem.source   # <-- returns the HTML as a string
Run Code Online (Sandbox Code Playgroud)

用于Python的selenium webdriver文档基本上不存在,我在代码中看不到任何似乎启用该功能的内容.

有关访问元素(及其子元素)的HTML的最佳方法的任何想法?

python selenium automated-tests webdriver selenium-webdriver

434
推荐指数
7
解决办法
38万
查看次数

使用Excel VBA从aspx页面表中检索数据

我正在尝试使用excel vba 从aspx页面检索表数据.我知道如何从URL获取表数据但下面是主要问题.

问题

有一个aspx页面(比如www.abc.aspx).我目前在此页面.请将此页面设为page1.

现在,我单击当前页面上的page2链接.什么是值得注意的是,点击该链接后,旧的URL(www.abc.aspx)不会改变,但内容的变化.(内容是第2页)

如果您查看它的page1源代码

<form method="post" action="page1 url" id="Form1">
Run Code Online (Sandbox Code Playgroud)

无论第1 (第2页点击)操作是什么,它都会回发相同的page1网址.

那么如何在excel VBA中获取page2 数据,因为我不知道它的URL?

这就是我用来获取表数据的方法.

我使用了Internet Explorer对象.然后导航到链接并将文档保存在htmldoc中.

ie.navigate "url"

Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Fetching data..."
DoEvents
Loop

Set htmldoc = ie.document

'Column headers
Set eleColth = htmldoc.getElementsByTagName("th")
j = 0 'start with the first value in the th collection
        For Each eleCol …
Run Code Online (Sandbox Code Playgroud)

asp.net excel vba http excel-vba

5
推荐指数
0
解决办法
1390
查看次数

使用已打开的网页(含硒)到beautifulsoup?

我打开了一个网页,并使用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

python selenium beautifulsoup

4
推荐指数
1
解决办法
3677
查看次数

如何从 Selenium Driver.PageSource 获取 HtmlAgilityPack.HtmlDocument?

我正在尝试将 HtmlAgilityPack 与 Selenium 一起使用。我想做一些测试,但不知道如何从 Selenium Driver.PageSource String 加载 HtmlDocument。有什么帮助吗?(c# 或 vb.net)

这里的代码...

Dim driver As IWebDriver
Dim ChromeOptions As New ChromeOptions
driver = New ChromeDriver("C:\ChromeDriver", ChromeOptions)
driver.Navigate.GoToUrl("www.Google.com")

Dim doc As New HtmlDocument
Dim wb As New HtmlWeb
doc = wb.LoadFromBrowser(driver.PageSource)
Run Code Online (Sandbox Code Playgroud)

注意我的问题是关于 Selenium 和 HtmlAgilityPack 之间的交互。

c# vb.net selenium html-agility-pack

2
推荐指数
1
解决办法
792
查看次数