python爬虫
山林里的迷路人
热爱Python,对大数据和机器学习相关内容感兴趣
展开
-
爬虫B站任意视频 弹幕文字+时间
import pandas as pdimport reimport requestsfrom bs4 import BeautifulSouptime_nature=[]comments=[]url = input('请输入B站视频链接: ')res = requests.get(url)cid = re.findall(r'"cid":(.*?),', res.text)[0] #其中cid是弹幕对应的idurl = f'https://comment.bilibili.c原创 2021-09-23 20:46:57 · 1751 阅读 · 2 评论 -
python爬虫-request库的使用
首先确保已经安装了request库pip install request调用get()方法实现与urlopen()相同的操作,得到一个response对象,然后分别输出1、response的类型2、状态码3、响应体的类型4、内容5、以及cookiesimport requestsr=requests.get('https://www.baidu.com/')print(type(r))print(r.status_code)print(r.text)print(r.cookies原创 2021-08-15 20:15:41 · 93 阅读 · 0 评论 -
python爬虫-股吧
import requestsfrom bs4 import BeautifulSoupimport timeheaders={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" }def parse_onepage(page): global count原创 2021-08-14 23:01:54 · 639 阅读 · 1 评论 -
python爬虫-京东商品评论
对京东某商品的评论进行爬虫并保存import randomfrom selenium import webdriverfrom selenium.webdriver import ActionChainsfrom selenium.webdriver.support.ui import WebDriverWaitimport timefrom bs4 import BeautifulSoupimport pandas as pdfrom selenium.webdriver.common.k原创 2021-08-14 22:59:22 · 391 阅读 · 0 评论 -
python爬虫——添加代理
在进行爬虫的时候,可能会需要添加代理from urllib.error import URLErrorfrom urllib.request import ProxyHandler,build_openerproxy_handler=ProxyHandler({ 'http':'http://127.0.0.1.8041', 'https':'https://127.0.0.1.8041',})opener=build_opener(proxy_handler)try:原创 2021-08-14 21:28:54 · 584 阅读 · 0 评论