Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Added URL to any hyperlinked text in a question or answer. #13

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Enhancement: Added URL to any hyperlinked text in a question or answer.
  • Loading branch information
mwwynne committed Jul 6, 2016
commit 5212adb26f33e1823593dbb45768fa43b9e82cc3
18 changes: 17 additions & 1 deletion socli/socli.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,25 @@ def get_stats(soup):
question_stats = (soup.find_all("span",class_="vote-count-post")[0].get_text())
question_stats = "Votes " + question_stats + " | " + (((soup.find_all("div",\
class_="module question-stats")[0].get_text()).replace("\n", " ")).replace(" "," | "))
question_desc = (soup.find_all("div", class_="post-text")[0].get_text())
question_desc = (soup.find_all("div", class_="post-text")[0])
add_urls(question_desc)
question_desc = question_desc.get_text()
question_stats = ' '.join(question_stats.split())
return question_tittle, question_desc, question_stats


def add_urls(tags):
"""
Adds the URL to any hyperlinked text found in a question
or answer.
"""
images = tags.find_all("a")

for image in images:
if hasattr(image, "href"):
image.string = "{} [{}]".format(image.text, image['href'])


# Display result page
def dispres(url):
res_page = requests.get(url + query, verify=False)
Expand All @@ -276,6 +290,8 @@ def dispres(url):
print(question_desc)
print("\t" + underline(question_stats))
try:
answer = (soup.find_all("div", class_="post-text"))[1]
add_urls(answer)
answer = (soup.find_all("div", class_="post-text")[1].get_text())
global tmpsoup
tmpsoup = soup
Expand Down