【发布时间】:2021-05-01 01:39:12
【问题描述】:
我想在下面的脚本中获取 id。阿尔萨
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
url = "https://www.beko.com.tr/cift-kapili-buzdolabi/b1-8459-smn-buzdolabi"
print(url)
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
id_all = soup.find_all('script')
print(id_all)
driver.close()
---------------output is more complex but I just want to get below 'id': '7291920212'------
</script>, <script>
dataLayer.push ({
'ecommerce' : {
'detail': {
'actionField': {'list': ''},
'products' : [
{
'name': 'B1 8459 SMN',
'id': '7291920212',
'brand': 'Beko',
'variant': 'Null',
'category': ''
}
]
},
【问题讨论】:
-
尝试使用
re模块,如下所示:stackoverflow.com/a/41757995/5805827 -
你可以通过请求来检索它。为什么要打扰硒?
标签: javascript python python-3.x web-scraping beautifulsoup