good_name = good.find_element_by_css_selector(
‘.p-name em’).text.replace(“\n”, “–”)
商品价格
good_price = good.find_element_by_class_name(
‘p-price’).text.replace(“\n”, “:”)
评价人数
good_commit = good.find_element_by_class_name(
‘p-commit’).text.replace(“\n”, " ")
good_content = f’‘’
商品链接: {good_url}
商品名称: {good_name}
商品价格: {good_price}
评价人数: {good_commit}
\n
‘’’
print(good_content)
with open(‘jd.txt’, ‘a’, encoding=‘utf-8’) as f:
f.write(good_content)
next_tag = driver.find_element_by_class_name(‘pn-next’)
next_tag.click()
time.sleep(2)
递归调用函数
get_good(driver)
time.sleep(10)
finally:
driver.close()
if name == ‘main’:
good_name = input(‘请输入爬取商品信息:’