from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import os
import requests
import pymysql
from pymysql.converters import escape_string
conn = pymysql.connect(
user="root",
password="plmoknijbuhv123.",
host="localhost",
database="kaoshi",
port=3306,
)
cursor = conn.cursor()
driver=Chrome()
url="https://www.dangdang.com/"
driver.get(url)
input=driver.find_element(By.XPATH,'//*[@id="key_S"]')
input.send_keys("Python")
danji=driver.find_element(By.XPATH,'//*[@id="form_search_new"]/input[10]')
danji.click()
flat=True
fd=open("html.csv",mode="a",encoding="utf-8")
sname = 1
xuhao="%05d"%1
while flat:
newurl=driver.current_url
myheaders={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}
response=requests.get(url=newurl,headers=myheaders)
response.encoding="GB2312"
html=response.text
soup=BeautifulSoup(html,'lxml')
ul=soup.find("ul",class_="bigimg")
lis=ul.find_all("li")
if not os.path.exists("download"):
os.mkdir("download")
i=1
for li in lis:
name=li.find("a")["title"]
try:
zuoze=li.find("p",class_="search_book_author").find("a")["title"]
except:
pass
money=li.find("p",class_="price").find("span",class_="search_now_price").text
riqi=li.find("p",class_="search_book_author").find_all("span")[1].text
chuban=li.find("p",class_="search_book_author").find_all("span")[2].text
jianjie=li.find("p",class_="detail").text
if i==1:
src=li.find("a").find("img")["src"]
else:
src=li.find("a").find("img")["data-original"]
movie_src="http:"+src
print(sname,name,zuoze)
resp=requests.get(movie_src,myheaders)
shu = "%05d" % sname
with open("download/"+str(shu)+".jpg","wb") as fp:
fp.write(resp.content)
fd.write(str(sname)+","+name+","+zuoze+","+chuban+","+riqi+","+money+","+jianjie+"\n")
sql="insert into kaoshi values (\'{}\',\'{}\',\'{}\',\'{}\',\'{}\',\'{}\');".format(escape_string(name),escape_string(zuoze),escape_string(chuban),escape_string(riqi),escape_string(money),escape_string(jianjie))
print(sql)
cursor.execute(sql)
conn.commit()
i=i+1
sname=sname+1
try:
next=driver.find_element(By.CLASS_NAME,"next").find_element(By.TAG_NAME,"a")
next.click()
except:
flat=False
fd.close()
cursor.close()
conn.close()
淮猪
- 粉丝: 131
- 资源: 7
最新资源
- 毕设和企业适用springboot区域电商平台类及物流信息平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及在线教育互动平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及智慧社区管理平台源码+论文+视频.zip
- 毕设和企业适用springboot人工智能类及企业数字资产管理平台源码+论文+视频.zip
- 毕设和企业适用springboot人工智能类及气象数据管理系统源码+论文+视频.zip
- 毕设和企业适用springboot人工智能类及企业风险监控平台源码+论文+视频.zip
- 毕设和企业适用springboot商城类及智能农业解决方案源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及VR互动平台源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及大数据存储平台源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及大数据实时处理系统源码+论文+视频.zip
- 毕设和企业适用springboot社交电商类及大数据云平台源码+论文+视频.zip
- 毕设和企业适用springboot全渠道电商平台类及电商产品推荐平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及智能云平台源码+论文+视频.zip
- 毕设和企业适用springboot区域电商平台类及自动化控制系统源码+论文+视频.zip
- 毕设和企业适用springboot全渠道电商平台类及个性化广告平台源码+论文+视频.zip
- 毕设和企业适用springboot全渠道电商平台类及酒店管理平台源码+论文+视频.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈