鱼C论坛

 找回密码
 立即注册
查看: 2269|回复: 18

[已解决]xdm,爬虫求助

[复制链接]
发表于 2021-6-6 01:27:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
python快期末了,快要交期末大作业了,但平时上课没好好听课,以及自学才刚学到类和对象,急需一份爬虫来完成大作业,如果有哪位朋友最近写了一份爬虫且有注释,希望可以借用一下,可以有偿,拜托了
最佳答案
2021-6-6 14:09:26
本帖最后由 小伤口 于 2021-6-6 14:10 编辑

这是我之前写的爬取京东评论和用户照片加上简单的可视化处理,你可以参考一下,
  1. import requests
  2. import json
  3. import queue
  4. import collections
  5. import threading
  6. import time
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. from matplotlib.font_manager import FontProperties
  10. dict_data = []
  11. dict_data2 = []
  12. dict_data3 = []
  13. zhao_pian = []
  14. # 创建多线程
  15. #爬取时间
  16. class MyThread_j(threading.Thread):
  17.     def __init__(self, q):
  18.         threading.Thread.__init__(self)
  19.         self.q = q
  20.     #调用get_index()
  21.     def run(self) -> None:
  22.         self.get_index()
  23.     def get_index(self):
  24.         url = self.q.get()
  25.         # 加请求头
  26.         headers = {
  27.             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
  28.         res = requests.get(url, headers=headers )
  29.         #处理数据
  30.         jd = json.loads(res.text.lstrip("fetchJSON_comment98(").rstrip(");"))
  31.         #将时间存在data2.txt文件中
  32.         for i in jd['comments']:
  33.             x_zuobiao=i['creationTime'].split(' ')
  34.             x_zuobiao=x_zuobiao[0].split('-')
  35.             x_zuobiao=x_zuobiao[0]+x_zuobiao[1]
  36.             with open("data2.txt", "a", encoding="utf-8") as file:
  37.                 file.write(x_zuobiao+ '\n')
  38. for i in range(5,10):
  39.     locals()['MyThread_j' + str(i)] = MyThread_j
  40. # 创建多线程
  41. #爬取评论
  42. class MyThread(threading.Thread):
  43.     def __init__(self, q):
  44.         threading.Thread.__init__(self)
  45.         self.q = q
  46.     # 调用get_index()
  47.     def run(self) -> None:
  48.         self.get_index()
  49.     def get_index(self):
  50.         url = self.q.get()
  51.         # 加请求头
  52.         headers = {
  53.             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
  54.         res = requests.get(url, headers=headers)
  55.         #处理数据
  56.         jd = json.loads(res.text.lstrip("jQuery593159(").rstrip(");"))
  57.         #将评论存在data.txt中
  58.         with open("data.txt", "a", encoding="utf-8") as file:
  59.             for i in jd['comments']:
  60.                 file.write(i['content'] + '\n')
  61.             #爬取照片并存在列表中
  62.             try:
  63.                 for each in i['images']:
  64.                     photo = each['imgUrl'].split('//')
  65.                     photo = photo[-1]
  66.                     photo = 'https://' + photo
  67.                     print(photo)
  68.                     zhao_pian.append(photo)
  69.             except:
  70.                 pass
  71. for i in range(5):
  72.     locals()['MyThread_' + str(i)] = MyThread
  73. def main(url_d):
  74.     # 创建队列存储url
  75.     q = queue.Queue()
  76.     url_d = url_d.split('/')
  77.     url_d = ''.join(url_d[-1])
  78.     url_d = url_d.split('.')
  79.     url_d = url_d[0]
  80.     for i in range(5):
  81.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(i) + "&pageSize=10&isShadowSku=0&fold=1"
  82.         q.put(url)
  83.         # 如果队列不为空,就继续爬
  84.         while not q.empty():
  85.             t = MyThread_j5(q)
  86.             t.start()
  87.             t.join()
  88.     for i in range(5,10):
  89.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  90.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  91.         q.put(url)
  92.         # 如果队列不为空,就继续爬
  93.         # 如果队列不为空,就继续爬
  94.         while not q.empty():
  95.             t_1 = MyThread_j6(q)
  96.             t_1.start()
  97.             t_1.join()
  98.     for i in range(10,15):
  99.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  100.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  101.         q.put(url)
  102.         # 如果队列不为空,就继续爬
  103.         # 如果队列不为空,就继续爬
  104.         while not q.empty():
  105.             t_2 = MyThread_j7(q)
  106.             t_2.start()
  107.             t_2.join()
  108.     for i in range(15,20):
  109.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  110.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  111.         q.put(url)
  112.         # 如果队列不为空,就继续爬
  113.         # 如果队列不为空,就继续爬
  114.         while not q.empty():
  115.             t_3 = MyThread_j8(q)
  116.             t_3.start()
  117.             t_3.join()
  118.     for i in range(20,25):
  119.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  120.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  121.         q.put(url)
  122.         # 如果队列不为空,就继续爬
  123.         # 如果队列不为空,就继续爬
  124.         while not q.empty():
  125.             t_4 = MyThread_j9(q)
  126.             t_4.start()
  127.             t_4.join()
  128.     for i in range(5):
  129.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=2&sortType=5&page=" + str(
  130.             i) + "&pageSize=10&pin=null&_=1616905936767"

  131.         q.put(url)
  132.         # 如果队列不为空,就继续爬
  133.         while not q.empty():
  134.             t = MyThread_0(q)
  135.             t.start()
  136.             t.join()
  137.     for i in range(10):
  138.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=1&sortType=5&page=" + str(
  139.             i) + "&pageSize=10&pin=null&_=1616905936767"
  140.         q.put(url)

  141.         # 如果队列不为空,就继续爬
  142.         # 如果队列不为空,就继续爬
  143.         while not q.empty():
  144.             t_1 = MyThread_1(q)
  145.             t_1.start()
  146.             t_1.join()
  147.     for i in range(10, 15):
  148.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=2&sortType=5&page=" + str(
  149.             i) + "&pageSize=10&pin=null&_=1616905936767"

  150.         q.put(url)
  151.         # 如果队列不为空,就继续爬
  152.         # 如果队列不为空,就继续爬
  153.         while not q.empty():
  154.             t_2 = MyThread_2(q)
  155.             t_2.start()
  156.             t_2.join()
  157.     for i in range(15, 20):
  158.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=3&sortType=5&page=" + str(
  159.             i) + "&pageSize=10&pin=null&_=1616905936767"
  160.         q.put(url)
  161.         # 如果队列不为空,就继续爬
  162.         # 如果队列不为空,就继续爬
  163.         while not q.empty():
  164.             t_3 = MyThread_3(q)
  165.             t_3.start()
  166.             t_3.join()
  167.     for i in range(20, 25):
  168.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=3&sortType=5&page=" + str(
  169.             i) + "&pageSize=10&pin=null&_=1616905936767"
  170.         q.put(url)
  171.         # 如果队列不为空,就继续爬
  172.         # 如果队列不为空,就继续爬
  173.         while not q.empty():
  174.             t_4 = MyThread_4(q)
  175.             t_4.start()
  176.             t_4.join()
  177.     #读取并保存照片
  178.     name = 0
  179.     for i in zhao_pian[:]:
  180.         r = requests.get(i)
  181.         name += 1
  182.         with open(str(name) + '.jpg', 'wb') as f:
  183.             f.write(r.content)
  184.     #将时间提取出来,并进行排序计数
  185.     with open("data2.txt") as file:
  186.         for line in file.readlines():
  187.             dict_data.append(int(line))
  188.     dict_data.sort()
  189.     dic = collections.Counter(dict_data)
  190.     for i in dic:
  191.         dict_data2.append(str(i))
  192.         dict_data3.append(dic[i])
  193.     #绘制折线图
  194.     x = np.array(dict_data2)
  195.     y = np.array(dict_data3)
  196.     fig=plt.figure(figsize=(25, 10))
  197.     fig.patch.set_facecolor('Turquoise')
  198.     ax = fig.add_subplot(111)
  199.     ax.patch.set_facecolor('DeepSkyBlue')
  200.     plt.plot(x, y, 'r')  # 折线 1 x 2 y 3 color
  201.     plt.plot(x, y, 'red', lw=2)  # 4 line w
  202.     plt.scatter(x, y, color='red', marker='o')
  203.     font = FontProperties(fname="mnjzbh.ttf")
  204.     plt.title("销售趋势(按时间顺序)", fontsize=24,fontproperties=font)
  205.     plt.xlabel("时间(年,月)", fontsize=14,fontproperties=font)
  206.     plt.ylabel("销售数量(件)", fontsize=14,fontproperties=font)
  207.     plt.savefig('Figure_1.png', bbox_inches='tight')
  208.     plt.show()
  209. if __name__ == '__main__':
  210.     url_d = input('输入网址:')
  211.     start_time = time.time()
  212.     main(url_d)
  213.     end_time = time.time()
  214.     print("耗时%d" % (end_time - start_time))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-6-6 03:02:56 | 显示全部楼层
  1. import requests
  2. import re
  3. import csv
  4. #设置查找条件
  5. obj = re.compile(r'<li>.*?<span class="title">(?P<name>.*?)</span>.*?<br>(?P<year>.*?)&nbsp.*?<span class="rating_num" '
  6.                  r'property="v:average">(?P<score>.*?)</span>.*?<span>(?P<num>.*?)人评价</span>',re.S)
  7. #设置请求头
  8. headers = {
  9.     'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36'
  10. }
  11. #输入流
  12. f = open('./imgs/top250电影排行榜.csv',mode='w',encoding="utf-8")
  13. csvwriter = csv.writer(f)
  14. #爬取数据
  15. for page in range(0,250,25):
  16.     #url地址
  17.     url = 'https://movie.douban.com/top250?start={}&filter='.format(page)
  18.     #发送请求
  19.     response = requests.get(url,headers=headers)
  20.     #获取页面信息
  21.     page_content = response.text
  22.     #查找需要爬取的内容
  23.     result = obj.finditer(page_content)
  24.     #将信息写入文件
  25.     for it in result:
  26.         dic = it.groupdict()
  27.         dic['year'] = dic['year'].strip()
  28.         csvwriter.writerow(dic.values())
  29. f.close()
  30. print('抓取完毕')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-6-6 08:39:48 | 显示全部楼层
具体问题是什么?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-6-6 08:42:13 | 显示全部楼层
suchocolate 发表于 2021-6-6 08:39
具体问题是什么?

没有具体问题,就是你想做什么就做什么,爬虫分会相对高点
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-6-6 08:45:45 From FishC Mobile | 显示全部楼层
形影似我遁无声 发表于 2021-6-6 08:42
没有具体问题,就是你想做什么就做什么,爬虫分会相对高点

最简单的爬虫也就几行代码,也能拿高分??
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-6-6 08:50:32 | 显示全部楼层
wp231957 发表于 2021-6-6 08:45
最简单的爬虫也就几行代码,也能拿高分??

那肯定是不能的,糊弄他也不能这么糊弄啊。但如果就做个游戏啥的,不管你做的多好,即使是你做了很久很精美的游戏,他也只会给个及格分,相比而言爬虫,数据可视化之类的好拿分多了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-6-6 09:46:07 | 显示全部楼层
981048327
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-6-6 10:03:25 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-6-6 14:09:26 | 显示全部楼层    本楼为最佳答案   
本帖最后由 小伤口 于 2021-6-6 14:10 编辑

这是我之前写的爬取京东评论和用户照片加上简单的可视化处理,你可以参考一下,
  1. import requests
  2. import json
  3. import queue
  4. import collections
  5. import threading
  6. import time
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. from matplotlib.font_manager import FontProperties
  10. dict_data = []
  11. dict_data2 = []
  12. dict_data3 = []
  13. zhao_pian = []
  14. # 创建多线程
  15. #爬取时间
  16. class MyThread_j(threading.Thread):
  17.     def __init__(self, q):
  18.         threading.Thread.__init__(self)
  19.         self.q = q
  20.     #调用get_index()
  21.     def run(self) -> None:
  22.         self.get_index()
  23.     def get_index(self):
  24.         url = self.q.get()
  25.         # 加请求头
  26.         headers = {
  27.             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
  28.         res = requests.get(url, headers=headers )
  29.         #处理数据
  30.         jd = json.loads(res.text.lstrip("fetchJSON_comment98(").rstrip(");"))
  31.         #将时间存在data2.txt文件中
  32.         for i in jd['comments']:
  33.             x_zuobiao=i['creationTime'].split(' ')
  34.             x_zuobiao=x_zuobiao[0].split('-')
  35.             x_zuobiao=x_zuobiao[0]+x_zuobiao[1]
  36.             with open("data2.txt", "a", encoding="utf-8") as file:
  37.                 file.write(x_zuobiao+ '\n')
  38. for i in range(5,10):
  39.     locals()['MyThread_j' + str(i)] = MyThread_j
  40. # 创建多线程
  41. #爬取评论
  42. class MyThread(threading.Thread):
  43.     def __init__(self, q):
  44.         threading.Thread.__init__(self)
  45.         self.q = q
  46.     # 调用get_index()
  47.     def run(self) -> None:
  48.         self.get_index()
  49.     def get_index(self):
  50.         url = self.q.get()
  51.         # 加请求头
  52.         headers = {
  53.             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
  54.         res = requests.get(url, headers=headers)
  55.         #处理数据
  56.         jd = json.loads(res.text.lstrip("jQuery593159(").rstrip(");"))
  57.         #将评论存在data.txt中
  58.         with open("data.txt", "a", encoding="utf-8") as file:
  59.             for i in jd['comments']:
  60.                 file.write(i['content'] + '\n')
  61.             #爬取照片并存在列表中
  62.             try:
  63.                 for each in i['images']:
  64.                     photo = each['imgUrl'].split('//')
  65.                     photo = photo[-1]
  66.                     photo = 'https://' + photo
  67.                     print(photo)
  68.                     zhao_pian.append(photo)
  69.             except:
  70.                 pass
  71. for i in range(5):
  72.     locals()['MyThread_' + str(i)] = MyThread
  73. def main(url_d):
  74.     # 创建队列存储url
  75.     q = queue.Queue()
  76.     url_d = url_d.split('/')
  77.     url_d = ''.join(url_d[-1])
  78.     url_d = url_d.split('.')
  79.     url_d = url_d[0]
  80.     for i in range(5):
  81.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(i) + "&pageSize=10&isShadowSku=0&fold=1"
  82.         q.put(url)
  83.         # 如果队列不为空,就继续爬
  84.         while not q.empty():
  85.             t = MyThread_j5(q)
  86.             t.start()
  87.             t.join()
  88.     for i in range(5,10):
  89.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  90.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  91.         q.put(url)
  92.         # 如果队列不为空,就继续爬
  93.         # 如果队列不为空,就继续爬
  94.         while not q.empty():
  95.             t_1 = MyThread_j6(q)
  96.             t_1.start()
  97.             t_1.join()
  98.     for i in range(10,15):
  99.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  100.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  101.         q.put(url)
  102.         # 如果队列不为空,就继续爬
  103.         # 如果队列不为空,就继续爬
  104.         while not q.empty():
  105.             t_2 = MyThread_j7(q)
  106.             t_2.start()
  107.             t_2.join()
  108.     for i in range(15,20):
  109.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  110.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  111.         q.put(url)
  112.         # 如果队列不为空,就继续爬
  113.         # 如果队列不为空,就继续爬
  114.         while not q.empty():
  115.             t_3 = MyThread_j8(q)
  116.             t_3.start()
  117.             t_3.join()
  118.     for i in range(20,25):
  119.         url = "https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=" + url_d + "&score=1&sortType=6&page=" + str(
  120.             i) + "&pageSize=10&isShadowSku=0&fold=1"
  121.         q.put(url)
  122.         # 如果队列不为空,就继续爬
  123.         # 如果队列不为空,就继续爬
  124.         while not q.empty():
  125.             t_4 = MyThread_j9(q)
  126.             t_4.start()
  127.             t_4.join()
  128.     for i in range(5):
  129.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=2&sortType=5&page=" + str(
  130.             i) + "&pageSize=10&pin=null&_=1616905936767"

  131.         q.put(url)
  132.         # 如果队列不为空,就继续爬
  133.         while not q.empty():
  134.             t = MyThread_0(q)
  135.             t.start()
  136.             t.join()
  137.     for i in range(10):
  138.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=1&sortType=5&page=" + str(
  139.             i) + "&pageSize=10&pin=null&_=1616905936767"
  140.         q.put(url)

  141.         # 如果队列不为空,就继续爬
  142.         # 如果队列不为空,就继续爬
  143.         while not q.empty():
  144.             t_1 = MyThread_1(q)
  145.             t_1.start()
  146.             t_1.join()
  147.     for i in range(10, 15):
  148.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=2&sortType=5&page=" + str(
  149.             i) + "&pageSize=10&pin=null&_=1616905936767"

  150.         q.put(url)
  151.         # 如果队列不为空,就继续爬
  152.         # 如果队列不为空,就继续爬
  153.         while not q.empty():
  154.             t_2 = MyThread_2(q)
  155.             t_2.start()
  156.             t_2.join()
  157.     for i in range(15, 20):
  158.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=3&sortType=5&page=" + str(
  159.             i) + "&pageSize=10&pin=null&_=1616905936767"
  160.         q.put(url)
  161.         # 如果队列不为空,就继续爬
  162.         # 如果队列不为空,就继续爬
  163.         while not q.empty():
  164.             t_3 = MyThread_3(q)
  165.             t_3.start()
  166.             t_3.join()
  167.     for i in range(20, 25):
  168.         url = "https://club.jd.com/comment/productPageComments.action?callback=jQuery593159&productId=" + url_d + "&score=3&sortType=5&page=" + str(
  169.             i) + "&pageSize=10&pin=null&_=1616905936767"
  170.         q.put(url)
  171.         # 如果队列不为空,就继续爬
  172.         # 如果队列不为空,就继续爬
  173.         while not q.empty():
  174.             t_4 = MyThread_4(q)
  175.             t_4.start()
  176.             t_4.join()
  177.     #读取并保存照片
  178.     name = 0
  179.     for i in zhao_pian[:]:
  180.         r = requests.get(i)
  181.         name += 1
  182.         with open(str(name) + '.jpg', 'wb') as f:
  183.             f.write(r.content)
  184.     #将时间提取出来,并进行排序计数
  185.     with open("data2.txt") as file:
  186.         for line in file.readlines():
  187.             dict_data.append(int(line))
  188.     dict_data.sort()
  189.     dic = collections.Counter(dict_data)
  190.     for i in dic:
  191.         dict_data2.append(str(i))
  192.         dict_data3.append(dic[i])
  193.     #绘制折线图
  194.     x = np.array(dict_data2)
  195.     y = np.array(dict_data3)
  196.     fig=plt.figure(figsize=(25, 10))
  197.     fig.patch.set_facecolor('Turquoise')
  198.     ax = fig.add_subplot(111)
  199.     ax.patch.set_facecolor('DeepSkyBlue')
  200.     plt.plot(x, y, 'r')  # 折线 1 x 2 y 3 color
  201.     plt.plot(x, y, 'red', lw=2)  # 4 line w
  202.     plt.scatter(x, y, color='red', marker='o')
  203.     font = FontProperties(fname="mnjzbh.ttf")
  204.     plt.title("销售趋势(按时间顺序)", fontsize=24,fontproperties=font)
  205.     plt.xlabel("时间(年,月)", fontsize=14,fontproperties=font)
  206.     plt.ylabel("销售数量(件)", fontsize=14,fontproperties=font)
  207.     plt.savefig('Figure_1.png', bbox_inches='tight')
  208.     plt.show()
  209. if __name__ == '__main__':
  210.     url_d = input('输入网址:')
  211.     start_time = time.time()
  212.     main(url_d)
  213.     end_time = time.time()
  214.     print("耗时%d" % (end_time - start_time))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-8-31 21:20:36 | 显示全部楼层
小伤口 发表于 2021-6-6 14:09
这是我之前写的爬取京东评论和用户照片加上简单的可视化处理,你可以参考一下,

请问这里运行不了该怎么解决 求指教
Exception in thread Thread-11:
Traceback (most recent call last):
  File "E:\新建文件夹\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:/Users/admin/Desktop/京东评论区.py", line 22, in run
    self.get_index()
  File "C:/Users/admin/Desktop/京东评论区.py", line 30, in get_index
    jd = json.loads(res.text.lstrip("fetchJSON_comment98(").rstrip(");"))
  File "E:\新建文件夹\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "E:\新建文件夹\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "E:\新建文件夹\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Exception in thread Thread-12:
Traceback (most recent call last):
  File "E:\新建文件夹\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:/Users/admin/Desktop/京东评论区.py", line 22, in run
    self.get_index()
  File "C:/Users/admin/Desktop/京东评论区.py", line 30, in get_index
    jd = json.loads(res.text.lstrip("fetchJSON_comment98(").rstrip(");"))
  File "E:\新建文件夹\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "E:\新建文件夹\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "E:\新建文件夹\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-8-31 23:48:14 | 显示全部楼层
arrexxxx 发表于 2021-8-31 21:20
请问这里运行不了该怎么解决 求指教
Exception in thread Thread-11:
Traceback (most recent ...

你现在再运行一下试试
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-1 07:31:42 | 显示全部楼层
小伤口 发表于 2021-8-31 23:48
你现在再运行一下试试

还是不能正常运行,输入网址后显示的是这个东西
输入网址:https://item.jd.com/10027959220343.html
https://img30.360buyimg.com/n0/s ... 08933aa4c629b55.jpg
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\京东评论区.py", line 215, in <module>
    main(url_d)
  File "C:\Users\admin\Desktop\京东评论区.py", line 210, in main
    plt.savefig('Figure_1.png', bbox_inches='tight')
  File "E:\新建文件夹\lib\site-packages\matplotlib\pyplot.py", line 966, in savefig
    res = fig.savefig(*args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\figure.py", line 3015, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
    self.figure.draw(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\figure.py", line 2790, in draw
    mimage._draw_list_compositing_images(
  File "E:\新建文件夹\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\axes\_base.py", line 2881, in draw
    self._update_title_position(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\axes\_base.py", line 2822, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "E:\新建文件夹\lib\site-packages\matplotlib\text.py", line 903, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\text.py", line 306, in _get_layout
    _, lp_h, lp_d = renderer.get_text_width_height_descent(
  File "E:\新建文件夹\lib\site-packages\matplotlib\backends\backend_agg.py", line 239, in get_text_width_height_descent
    font = self._get_agg_font(prop)
  File "E:\新建文件夹\lib\site-packages\matplotlib\backends\backend_agg.py", line 274, in _get_agg_font
    font = get_font(fname)
  File "E:\新建文件夹\lib\site-packages\matplotlib\font_manager.py", line 1424, in get_font
    return _get_font(filename, hinting_factor,
  File "E:\新建文件夹\lib\site-packages\matplotlib\font_manager.py", line 1405, in _get_font
    return ft2font.FT2Font(
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\admin\\Desktop\\mnjzbh.ttf'
>>>
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-1 07:32:34 | 显示全部楼层
小伤口 发表于 2021-8-31 23:48
你现在再运行一下试试

还是不行,输入网址后显示的是这样

https://img30.360buyimg.com/n0/s ... 08933aa4c629b55.jpg
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\京东评论区.py", line 215, in <module>
    main(url_d)
  File "C:\Users\admin\Desktop\京东评论区.py", line 210, in main
    plt.savefig('Figure_1.png', bbox_inches='tight')
  File "E:\新建文件夹\lib\site-packages\matplotlib\pyplot.py", line 966, in savefig
    res = fig.savefig(*args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\figure.py", line 3015, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
    self.figure.draw(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\figure.py", line 2790, in draw
    mimage._draw_list_compositing_images(
  File "E:\新建文件夹\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\axes\_base.py", line 2881, in draw
    self._update_title_position(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\axes\_base.py", line 2822, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "E:\新建文件夹\lib\site-packages\matplotlib\text.py", line 903, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\text.py", line 306, in _get_layout
    _, lp_h, lp_d = renderer.get_text_width_height_descent(
  File "E:\新建文件夹\lib\site-packages\matplotlib\backends\backend_agg.py", line 239, in get_text_width_height_descent
    font = self._get_agg_font(prop)
  File "E:\新建文件夹\lib\site-packages\matplotlib\backends\backend_agg.py", line 274, in _get_agg_font
    font = get_font(fname)
  File "E:\新建文件夹\lib\site-packages\matplotlib\font_manager.py", line 1424, in get_font
    return _get_font(filename, hinting_factor,
  File "E:\新建文件夹\lib\site-packages\matplotlib\font_manager.py", line 1405, in _get_font
    return ft2font.FT2Font(
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\admin\\Desktop\\mnjzbh.ttf'
>>>
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-1 11:31:15 | 显示全部楼层
小伤口 发表于 2021-8-31 23:48
你现在再运行一下试试

还是没有过 只能打出图片
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-1 11:32:53 | 显示全部楼层
arrexxxx 发表于 2021-9-1 11:31
还是没有过 只能打出图片

Traceback (most recent call last):
  File "C:\Users\admin\Desktop\京东评论区.py", line 215, in <module>
    main(url_d)
  File "C:\Users\admin\Desktop\京东评论区.py", line 210, in main
    plt.savefig('Figure_1.png', bbox_inches='tight')
  File "E:\新建文件夹\lib\site-packages\matplotlib\pyplot.py", line 966, in savefig
    res = fig.savefig(*args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\figure.py", line 3015, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
    self.figure.draw(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\figure.py", line 2790, in draw
    mimage._draw_list_compositing_images(
  File "E:\新建文件夹\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "E:\新建文件夹\lib\site-packages\matplotlib\axes\_base.py", line 2881, in draw
    self._update_title_position(renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\axes\_base.py", line 2822, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "E:\新建文件夹\lib\site-packages\matplotlib\text.py", line 903, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "E:\新建文件夹\lib\site-packages\matplotlib\text.py", line 306, in _get_layout
    _, lp_h, lp_d = renderer.get_text_width_height_descent(
  File "E:\新建文件夹\lib\site-packages\matplotlib\backends\backend_agg.py", line 239, in get_text_width_height_descent
    font = self._get_agg_font(prop)
  File "E:\新建文件夹\lib\site-packages\matplotlib\backends\backend_agg.py", line 274, in _get_agg_font
    font = get_font(fname)
  File "E:\新建文件夹\lib\site-packages\matplotlib\font_manager.py", line 1424, in get_font
    return _get_font(filename, hinting_factor,
  File "E:\新建文件夹\lib\site-packages\matplotlib\font_manager.py", line 1405, in _get_font
    return ft2font.FT2Font(
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\admin\\Desktop\\mnjzbh.ttf'
>>>
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-1 11:33:36 | 显示全部楼层
小伤口 发表于 2021-8-31 23:48
你现在再运行一下试试

打印图片之后是这样子的报错T T
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-1 11:43:26 | 显示全部楼层
arrexxxx 发表于 2021-9-1 11:33
打印图片之后是这样子的报错T T

评论也是能打出来的,但是不明白为啥还是会报错。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-1 12:25:14 From FishC Mobile | 显示全部楼层
arrexxxx 发表于 2021-9-1 11:33
打印图片之后是这样子的报错T T

这个是正常现象因为好像这个方法要弃用了,所以会显示这个
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-19 09:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表