Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 规范化seleniumpython中的空间_Css_Selenium_Xpath_Web Scraping_Scrapy - Fatal编程技术网

Css 规范化seleniumpython中的空间

Css 规范化seleniumpython中的空间,css,selenium,xpath,web-scraping,scrapy,Css,Selenium,Xpath,Web Scraping,Scrapy,我正试图从网络上获取产品名称信息。HTML格式如下: <div class="p-name p-name-type-2"> <em xpath="1" style> "Apple" <font class="skcolor_ljg">iPad</font> <font class="skcolor_

我正试图从网络上获取产品名称信息。HTML格式如下:

<div class="p-name p-name-type-2">
    <em xpath="1" style>
        "Apple"
        <font class="skcolor_ljg">iPad</font>
        <font class="skcolor_ljg">Air</font>
        <font class="skcolor_ljg">3</font>
        64G WLAN Grey
    </em>
</div>
我不确定Selenium的语法是如何工作的。 我试过:

但它不会将name_temp作为我在第一行中定义的变量。 我还尝试:

product_name_jd = element.find_element_by_css_selector('.p-name-type-2 em').text
tmallSpider.items = tmallSpider.items['product_name_jd'] = product_name_jd
product_price_jd = element.find_element_by_css_selector('.p-price i').text
tmallSpider.items = tmallSpider.items['product_price_jd'] = product_price_jd
yield tmallSpider.items
但这给了我一个错误:

TypeError: 'str' object does not support item assignment

知道如何获得产品名称吗?

试试这个:

product_name_jd = driver.find_element_by_css_selector('div.p-name.p-name-type-2').text
print(product_name_jd.split('"')[-1].strip())
TypeError: 'str' object does not support item assignment

product_name_jd = driver.find_element_by_css_selector('div.p-name.p-name-type-2').text
print(product_name_jd.split('"')[-1].strip())