-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay45.py
83 lines (42 loc) · 1.22 KB
/
Day45.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from bs4 import BeautifulSoup
import requests
response = requests.get("https://news.ycombinator.com/newest")
web_page = response.text
soup = BeautifulSoup(web_page, 'html.parser')
scores = []
score = soup.find_all(name="span", class_="score")
for tag in score:
scores.append(tag.text)
# anchor_text = soup.select(selector='span', class_="titleline")
# for tag in anchor_text:
# print(tag.find_all(name="a", limit=1))
def has_sub(css_class):
return css_class is not None and "https" in css_class
news= [ ]
anchor = soup.find_all(href=has_sub, class_="")
for tag in anchor:
news.append(tag.text)
print(news)
print(scores)
# print(anchor_text.get("text"))
# for tag in anchor_text:
# print(tag.getText())
'''
with open("Day41.html", encoding="utf8" ) as file:
content = file.read()
soup = BeautifulSoup(content, "lxml")
# print(soup.title)
# print(soup.title.name)
# print(soup.title.string)
# print(soup.prettify())
all_tag = soup.find_all(name="a")
# print(all_tag)
for tag in all_tag:
# print(tag.getText())
# print(tag.get('href'))
pass
tag_With_class = soup.find(name="h2", id="hello")
# print(tag_With_class.text)
a_tag = soup.select_one(selector="ul a")
print(a_tag)
'''