Reply content:
For an example of av2047063, visit the following URL: "The URL has been hidden"
@ Sister empty sauce reminds me to remember ....
First to apply for a appkey ... Over here:
Bilibili-Tips
Then you can do whatever you like with Bilibiliapi ....
B Station The third-party client is so developed ...
You can see the last two parameters Id=av number &page= p
The number of plays is 18253 after play.
==============================
B Station has public API Ah .... So why bother? The first time the Lord has been handed in here,,,
———————————————————————————————————————
Shortly before I learned Python, just to review
The code is as follows:
Import Re,urllib
Page=urllib.urlopen (' / http m.acg.tv/video/av204604 0.html
')
Html=page.read ()
Re_times=r '
(.*)'
result = Re.findall (re_times,html)
Re_title=r '
(.*)
'
Title=re.findall (re_title,html)
Print title[0], ' played as ', Result[0]
Let's take av2046040 as an example: http://www. BILIBILI.COM/VIDEO/AV20 46040/
Can see
use Firefox to view the selected source code, as follows Use Firefox to view the selected source code, as follows
but I didn't get the page content through the Python urllib module: But I didn't get the page content through the Python urllib module:
Page=urllib.urlopen (' http://www.bilibili.com/video/av2046040/
')
so I switched ideas, seemingly B station mobile version of the page can be, So I switched ideas, seemingly B station mobile version of the page can be,
Then use Firefox's user-agent overrider to modify the browser UA for Android Firefox/29
you can get the following interface: You can get the following interface:
Once you get to the actual page address, you can use Firefox to view the source code again. Once you get to the actual page address, you can use Firefox to view the source code again.
you can write a regular expression: You can write a regular expression:
Re_times=r '
(.*)'
Then the regular match would be fine.
# Encoding=utf8# Author:shell-vonImport RequestsImport ReAid = ' 3210612 'Api_key = "Http://interface.bilibili.com/count?key=27f582250563d5d6b11d6833&aid=%s"Data = Requests.Get(Api_key % Aid).contentRegex = r "\ (' (?:. | #) ([\w_]+) ' \) \.html\ ('? ( (\d+) '? \) 'Print Dict(Re.FindAll(Regex, Data))
Once wrote a ....
Haogefeifei/get_bilibili_anime GitHub
This is the crawl of MATLAB, where the API can be obtained using Chrome's developer tools:
aid=3295561;api='http://interface.bilibili.com/count?key=b9415053057bb00966665eaa';data=regexp(webread(api,'aid',aid),'#(\w)+\D*(\d)+','tokens');data=[data{:}]
That's probably the idea.
0, open a specific AV page, through this statement to find the CID and aid. Note: The source code that can be seen in Ctrl + U is the one that matches.
1, send the request to Interface.bilibili.com/player?id=cid: (Matching CID, to the front of the colon) &aid=
(Matching aid)
2. Found in the obtained XML file , that's the answer you asked for.
=====================================================
In fact, the page we see in Ctrl + U is one of the packages sent to us by the site, and the final result page is the result of multiple package combinations sent to us by the site.
Sometimes, the website encapsulates the data in JSON or XML, then gets the data through multiple requests, and finally constructs it locally with JS.
So, what you see on the page is the final result, and if you want to determine whether the result is from a source page or JSON or XML, you need to grab the package from the developer tools and analyze it yourself.
In short, the logic is:
0. Where did this data come from? --By Grasping packet analysis
1. Simulate the process of acquiring this data. --direct access to the source URL of the data
And, of course, pay attention to the parameters you want to pass. Where this parameter is obtained from and needs to be analyzed by itself.
====================================================
Let me give you an example.
Note: The data sent back by station B is gzip, however Urllib2 's urlopen is not automatically decompressed and needs to be handled manually.
You can refer to this answer:
Does python urllib2 automatically uncompress gzip data fetched from webpage?
Find a page on the homepage, the address is as follows:
"Love deep black cut" passers-by female master's play Bad method ~ First Play
Import urllib2import refrom stringio import stringioimport gzipdef find_cid_aid (HTML): target = Re.compile (' Embedplayer (? P.*?)', Re. Dotall) Cidaid = target.search (html) cidaid = Html[cidaid.start (' args '): Cidaid.end (' args ')] cid = Cidaid.find (' CI d= ') aid = cidaid.find (' &aid= ') index = aid while cidaid[index]! = ' "': Index + = 1 return (cidaid[c ID + 4:aid],cidaid[aid + 5:index]) def find_how_many (cid_aid): target = Re.compile (R '
(?
P
. *?)
', Re. Dotall) cid = cid_aid[0] aid = cid_aid[1] Addr = R ' http://interface.bilibili.com/player?id=cid: ' + cid + ' &ai D= ' + aid F = urllib2.urlopen (addr) res = F.read () target = Target.search (res) return Res[target.start (' result '): target.end (' result ')]headers = {' Accept ': ' text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ', \ ' Accept-language ': ' zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 ', \ ' user-agent ': ' mozilla/5.0 (Windows NT 6.1; rv:28.0) gecko/20100101 firefox/28.0 ', \ ' Host ': ' www.bilibili.com ', \ ' accept-encoding ': ' gzip, deflate ', \ ' Cache-control ': ' max-age=0 ', \ ' Connection ': ' keep-alive '}request = urllib2. Request (R ' http://www.bilibili.com/video/av2046145/', headers=headers) HTML = urllib2.urlopen (Request) if Html.info () . Get (' content-encoding ') = = ' gzip ': buf = Stringio (Html.read ()) F = gzip. Gzipfile (fileobj=buf) HTML = f.read () Cid_aid = find_cid_aid (HTML) print Find_how_many (cid_aid)
Get CID aid Request Http://interface.bilibili.com/player
I'll know what's in the bag.
For example, the same lazy glasses, you know ~ ~
The source code here directly can be directly matched to the CID and aid,
cid=1511100&aid=1044050
Then request
http/ interface.bilibili.com/ player?id=cid:1511100&aid=1044050
Then be It's just the number of players that surround you.
4611
Everything you see on the computer screen is data. The website of station B is just a bunch of code. Get a little bit of source code, gzip compression, convert the code, regular expression search, you can come out, very simple.