与美丽的小组及其隔离刮擦&硒
我正在尝试从HREF获取“ Master_key”。有人可以帮助我隔离文字中的钥匙吗?理想情况下,我将能够运行一个find_all并获得所有可用的find_all。谢谢!!
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import requests
options = Options()
options.headless = False
driver = webdriver.Firefox(options=options)
driver.get("https://annual.asaecenter.org/expo.cfm?")
driver.find_element(By. XPATH, "//*[@id='clickAgreeCookie']").click()
driver.find_element(By. XPATH, "//*[@id='search_table']/tbody/tr[7]/td[2]/input[2]").click()
page = bs(driver.page_source, 'html.parser')
key = page.find("a", href="javascript:void(0)")
print(key)
输出:
<a href="javascript:void(0)" onclick="javascript:ExhibitorPopup('profile.cfm?profile_name=exhibitor&master_key=F4DAF300-9A26-4024-9E49-3E29116E5A36&inv_mast_key=93A17E5D-A46F-F21E-77E4-77B38A3B30EE&xtemplate','exhibitor_profile');;analytics(1,'','F4DAF300-9A26-4024-9E49-3E29116E5A36')">108 Ideaspace</a>
所需输出:
F4DAF300-9A26-4024-9E49-3E29116E5A36
I am trying to grab a "master_key" from an href. Could someone please help me isolate the key out of the text? Ideally, I would be able to run a find_all and get all the ones available. Thanks!!
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import requests
options = Options()
options.headless = False
driver = webdriver.Firefox(options=options)
driver.get("https://annual.asaecenter.org/expo.cfm?")
driver.find_element(By. XPATH, "//*[@id='clickAgreeCookie']").click()
driver.find_element(By. XPATH, "//*[@id='search_table']/tbody/tr[7]/td[2]/input[2]").click()
page = bs(driver.page_source, 'html.parser')
key = page.find("a", href="javascript:void(0)")
print(key)
Output:
<a href="javascript:void(0)" onclick="javascript:ExhibitorPopup('profile.cfm?profile_name=exhibitor&master_key=F4DAF300-9A26-4024-9E49-3E29116E5A36&inv_mast_key=93A17E5D-A46F-F21E-77E4-77B38A3B30EE&xtemplate','exhibitor_profile');;analytics(1,'','F4DAF300-9A26-4024-9E49-3E29116E5A36')">108 Ideaspace</a>
Desired output:
F4DAF300-9A26-4024-9E49-3E29116E5A36
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将必须使用正则。使用内置 re 模块。例如:
这将搜索“ master_key =”和“&amp; amp”之间的所有文本。
在您的情况下,您需要使用:
输出:
You'll have to use regex. using the built-in re module. For example:
This searches for all the text between "master_key=" and "&".
In your case, you'll need to use:
Output: