[Python & 爬虫]爬取微博热搜,并应用在QQ机器人实现定时播报
程序员文章站
2022-06-15 20:18:43
效果如图:黑框程序代码:from selenium import webdriverfrom lxml import htmlfrom PIL import Imagefrom selenium.webdriver.support.select import Selectfrom lxml import etreeimport requestsimport reimport urllibimport timeimport cv2import pytesseractimport...
效果如图:
黑框程序代码:
from selenium import webdriver
from lxml import html
from PIL import Image
from selenium.webdriver.support.select import Select
from lxml import etree
import requests
import re
import urllib
import time
import cv2
import pytesseract
import socket
import numpy as np
def SATRT():
#访问
Url_ReSou = 'https://s.weibo.com/top/summary?retcode=6102'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = {'User-Agent':user_agent}
r = requests.get(Url_ReSou,headers=headers)
s_1 = etree.HTML(r.text)
#制作xpath内容
for i in range(21):
Xpath = '//*[@id="pl_top_realtimehot"]/table/tbody/tr['+ str(i + 1) +']/td[2]/a/text()'
if i == 0:
Head = '置顶:'
else:
Head = str(i) + ':'
ReSou_Result = Head + str(s_1.xpath(Xpath))
print(ReSou_Result)
if __name__ == "__main__":
SATRT()
本文地址:https://blog.csdn.net/qq_34916678/article/details/107647859