day03 爬取京东商品信息

day03 爬取京东商品信息,第1张

概述‘‘‘初级版: form tank!‘‘‘import timefrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver = webdriver.Chrome()try: driver.implicitly_wait(10)
‘‘‘初级版:    form tank!‘‘‘import timefrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver = webdriver.Chrome()try:    driver.implicitly_wait(10)    #往京东发送请求    driver.get(http://www.jd.com/)    #往京东主页输入框输入墨菲定律,按回车键    input_tag = driver.find_element_by_ID(key)    input_tag.send_keys(墨菲定律)    input_tag.send_keys(Keys.ENTER)    time.sleep(5)    #Js_code = ‘‘‘    #window.    #‘‘‘    good_List = driver.find_elements_by_class_name(gl-item)    for good in good_List:        #print(good)        #商品名称        good_name = good.find_element_by_CSS_selector(.p-name em).text        print(good_name)        #商品链接        good_url = good.find_element_by_CSS_selector(p-name a).get_attribute(href)        print(good_url)        #商品价格        good_price = good.find_element_by_CSS_selector(p-price).text        #print(good_price)        #商品评价        good_commit = good.find_element_by_CSS_selector(p_commit).text        good_content = f‘‘‘        商品名称:{good_name}        商品链接:{good_url}        商品价格:{good_price}        商品评价:{good_commit}        \n        ‘‘‘        print(good_content)        with open(jd.txt,a,enCoding=utf-8)as f:            f.write(good_content)    print(商品信息写入成功)finally:    driver.close()

 

‘‘‘狂暴版‘‘‘import timefrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver = webdriver.Chrome()try:    driver.implicitly_wait(10)    #往京东发送请求    driver.get(http://www.jd.com/)    #往京东主页输入框输入墨菲定律,按回车键    input_tag = driver.find_element_by_ID(key)    input_tag.send_keys(墨菲定律)    input_tag.send_keys(Keys.ENTER)    time.sleep(5)    #Js_code = ‘‘‘    #window.    #‘‘‘    good_List = driver.find_elements_by_class_name(gl-item)    for good in good_List:        #print(good)        #商品名称        good_name = good.find_element_by_CSS_selector(.p-name em).text        print(good_name)        #商品链接        good_url = good.find_element_by_CSS_selector(p-name a).get_attribute(href)        print(good_url)        #商品价格        good_price = good.find_element_by_CSS_selector(p-price).text        #print(good_price)        #商品评价        good_commit = good.find_element_by_CSS_selector(p_commit).text        good_content = f‘‘‘        商品名称:{good_name}        商品链接:{good_url}        商品价格:{good_price}        商品评价:{good_commit}        \n        ‘‘‘        print(good_content)        with open(jd.txt,enCoding=utf-8)as f:            f.write(good_content)    print(商品信息写入成功)finally:    driver.close()
总结

以上是内存溢出为你收集整理的day03 爬取京东商品信息全部内容,希望文章能够帮你解决day03 爬取京东商品信息所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1065851.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存