使用Selenium Python以元组形式收集数据

2024-09-26 17:54:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用seleniumpython3.6收集元组数据时遇到了一个问题。这是我要收集数据的页面(http://www.bobaedream.co.kr/cyber/CyberCar.php?gubun=I) 我想收集“制造商(制造商)”的数据在搜索菜单在页面的上部。在

enter image description here

我使用selenium webdrive设置虚拟页面,并使用以下代码收集和选择第一个下拉菜单的列表:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException

from bs4 import BeautifulSoup
from time import sleep


link = 'http://www.bobaedream.co.kr/cyber/CyberCar.php?gubun=I'
driver = webdriver.PhantomJS()
driver.set_window_size(1920, 1080)
driver.get(link)
sleep(.75)

soup = BeautifulSoup(driver.page_source, "html.parser", from_encoding='utf-8')

manufacturers = [
    ('%s', '%s') % (o.text, o.get_attribute('href'))
    for o
    in driver.find_elements_by_css_selector("#layer_maker ul.list li a")
    if o.text != '전체']

for manufacturer in manufacturers:
    driver.execute_script("o.get_attribute('href')")

这是我收到的错误信息:

^{pr2}$

请帮忙。在


Tags: 数据fromimporthttpsupportgetwwwdriver
1条回答
网友
1楼 · 发布于 2024-09-26 17:54:40

我想这就是你需要的:

[
('%s' % o.text, '%s' % o.get_attribute('href'))
for o
in driver.find_elements_by_css_selector("#layer_maker ul.list li a")
if o.text != '전체']

或者只是

^{pr2}$

注意,%也是Python中的一个“模”运算符,不能应用于元组

相关问题 更多 >

    热门问题