【问题标题】:Scrape combobox刮擦组合框
【发布时间】:2021-03-29 06:00:14
【问题描述】:

目标

这里的每个组合:https://www.repuestoscoches24.es/

我要问什么

关于如何进行的任何提示。

具体问题

带有 4 个下拉菜单的组合框,我可以获取第一个选项的列表,但无法传递值来获取第二个选项。

我做了什么

# %%
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
import pandas as pd


# %% DRIVER
driver = webdriver.Edge(executable_path=r"E:\msedgedriver.exe")


# %% URL
driver.get(r'https://www.repuestoscoches24.es/')


# %% TO FILL
cars = pd.DataFrame(columns=["MAKE", "YEAR", "MODEL", "MOTOR"])


# %% MAKE LIST
makesearch = driver.find_element_by_xpath(r'//select')
dropdownmake = Select(makesearch)
makeoption = dropdownmarca.options
makes = []
for make in makeoption:
    listamarcas.append(make.text)
makeoption = None


# %% NOT LOOPING THROUGH MAKES FOR DEBUGGING
# THIS CODE SHOULD BRING ALL YEAR OPTIONS BY MAKE
dropdownmake.select_by_visible_text("ABARTH")  # DEBUG
yearsearch = driver.find_element_by_xpath(r'//*[contains(concat( " ", @class, " " ), concat( " ", "js-year", " " ))] | //select')
dropdownyear = Select(yearsearch)
yearoption = dropdownmarca.options
for year in yearoption:
    print(year.text)

【问题讨论】:

    标签: python selenium web-scraping


    【解决方案1】:

    https://www.repuestoscoches24.es/ajax/selector/car_selector.json 的HTTP POST 返回您要查找的数据。
    HTTP POST https://www.repuestoscoches24.es/ajax/selector/car_selector.json 结果见https://pastebin.com/2Zdt2NT1
    使用浏览器开发工具查看需要将哪些标头传递给 HTTP 调用才能获取数据。

    【讨论】:

    • 你检查过json吗?你在那里找到你正在寻找的信息吗?没有代码......我从 Chrome 开发工具中得到了一切。 F12 - 网络 - XHR
    • 谢谢,我只是为了以防万一。我明天会看到这个问题。
    猜你喜欢
    • 1970-01-01
    • 2020-01-09
    • 2021-09-06
    • 2014-08-10
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多