Small adjustment to stackoverflow example
This commit is contained in:
@@ -11,13 +11,15 @@ page = Adaptor(response.text, url=response.url)
|
|||||||
# First we will extract the first question title and its author based on the text content
|
# First we will extract the first question title and its author based on the text content
|
||||||
first_question_title = page.find_by_text('Run Selenium Python Script on Remote Server')
|
first_question_title = page.find_by_text('Run Selenium Python Script on Remote Server')
|
||||||
first_question_author = page.find_by_text('Ryan')
|
first_question_author = page.find_by_text('Ryan')
|
||||||
# If you want you can extract other questions tags like below
|
# because this page changes a lot
|
||||||
first_question = first_question_title.find_ancestor(
|
if first_question_title and first_question_author:
|
||||||
lambda ancestor: ancestor.attrib.get('id') and 'question-summary' in ancestor.attrib.get('id')
|
# If you want you can extract other questions tags like below
|
||||||
)
|
first_question = first_question_title.find_ancestor(
|
||||||
rest_of_questions = first_question.find_similar()
|
lambda ancestor: ancestor.attrib.get('id') and 'question-summary' in ancestor.attrib.get('id')
|
||||||
# But since nothing to rely on to extract other titles/authors from these elements without CSS/XPath selectors due to the website nature
|
)
|
||||||
# We will get all the rest of the titles/authors in the page depending on the first title and the first author we got above as a starting point
|
rest_of_questions = first_question.find_similar()
|
||||||
for i, (title, author) in enumerate(zip(first_question_title.find_similar(), first_question_author.find_similar()), start=1):
|
# But since nothing to rely on to extract other titles/authors from these elements without CSS/XPath selectors due to the website nature
|
||||||
print(i, title.text, author.text)
|
# We will get all the rest of the titles/authors in the page depending on the first title and the first author we got above as a starting point
|
||||||
|
for i, (title, author) in enumerate(zip(first_question_title.find_similar(), first_question_author.find_similar()), start=1):
|
||||||
|
print(i, title.text, author.text)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user