-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from pyconjp/t210-webapi
refs #210 update api and scraping
- Loading branch information
Showing
3 changed files
with
96 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import requests | ||
|
||
|
||
def main(): | ||
params = { | ||
'keyword': 'python', | ||
'ym': '202305', | ||
} | ||
url = 'https://connpass.com/api/v1/event/' | ||
user_agent = "Mozilla/5.0" # デフォルトのUser-Agentだと403 Forbiddenとなる | ||
r = requests.get(url, params=params, headers={"User-Agent": user_agent}) | ||
event_info = r.json() # レスポンスのJSONを変換 | ||
|
||
print('件数:', event_info['results_returned']) # 件数を表示 | ||
for event in event_info['events']: | ||
print(event['title']) | ||
print(event['started_at']) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
def main(): | ||
url = 'https://docs.python.org/ja/3.10/library/functions.html' | ||
res = requests.get(url) | ||
content = res.content | ||
soup = BeautifulSoup(content, 'html.parser') | ||
functions = soup.find_all('dl', class_='py function') | ||
print('件数:', len(functions)) | ||
for func in functions: | ||
func_name = func.dt.code.text | ||
|
||
# 上記記述だと@staticmethodの関数名が正しく取れないので、取りたい場合はこちら | ||
# func_name = func.dt.find_all('code', class_='sig-name')[0].text | ||
|
||
print(func_name) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |