Python Selenium代码无法从ashion.com.cn中删除
我正在使用pythonPython Selenium代码无法从ashion.com.cn中删除,python,python-3.x,selenium,selenium-webdriver,Python,Python 3.x,Selenium,Selenium Webdriver,我正在使用pythonselenium构建一个web刮板。该脚本删除了amazon、stack overflow和flipcart等网站,但无法删除Ashion。它总是返回一个空白的.csv文件 这是我的代码: from selenium import webdriver from selenium.webdriver.chrome.options import Options import pandas as pd import time user_agent = 'Mozilla/5.0
selenium
构建一个web刮板。该脚本删除了amazon、stack overflow和flipcart等网站,但无法删除Ashion。它总是返回一个空白的.csv文件
这是我的代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import pandas as pd
import time
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) ' \
'Chrome/80.0.3987.132 Safari/537.36'
driver_exe = 'chromedriver'
options = Options()
#options.add_argument("--headless")
options.add_argument(f'user-agent={user_agent}')
options.add_argument("--disable-web-security")
options.add_argument("--allow-running-insecure-content")
options.add_argument("--allow-cross-origin-auth-prompt")
driver = webdriver.Chrome(executable_path=r"C:\Users\intel\Downloads\Setups\chromedriver.exe", options=options)
driver.get("https://www.ofashion.com.cn/goods/10001?t=15777838840003")
class_Name = "." + "ellipsis-single ware-brand"
x = driver.find_elements_by_css_selector(class_Name.replace(' ','.'))
web_content_list = []
for i in x:
web_content_dict = {}
web_content_dict["Title"] = i.text
web_content_list.append(web_content_dict)
df = pd.DataFrame(web_content_list)
df.to_csv(r'C:\Users\intel\Desktop\data_file.csv',
index=False, mode='a', encoding='utf-8')
任何帮助都将不胜感激 这是因为网站是通过javascript加载的。你看到那个装货标志了吗?如果您查看选项卡顶部,您可以看到页面不再加载。要等待它完全加载,可以使用 注意:请在代码末尾放置
driver.close()
以正确关闭chromedriver
窗口