Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

python - Trying to create a web scraper, but the code below keeps printing all html

So im trying to pull my stats from medium.com and have already built a bot to log in, when i get to the stats page and try to print the title, it keeps throwing all the html at me. The print function is there to make sure it's printing the right stuff before I move on:

url = driver.page_source
headers = {"Accept-Language": "en-US, en;q=0.5"}
results = requests.get(url, headers=headers)

soup = BeautifulSoup(url, "lxml")

story_title = []
publication = []
views = []
reads = []
read_ratio = []
fans = []

stats_div = soup.find_all('tr', class_='sortableTable-row js-statsTableRow')
for container in stats_div:
    name = container.td.a.text.find('span', class_='sortableTable-title u-maxWidth450')
    story_title.append(name)

print(story_title)
question from:https://stackoverflow.com/questions/65830087/trying-to-create-a-web-scraper-but-the-code-below-keeps-printing-all-html

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Nevermind, got it! Selenium didn't like url = driver.page_source so I just used the link instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...