1

I want to build a small project on Web Scraping.

During Hacktoberfest or say GSOC when contributors need to solve more number of issues they prefer easy issues like the ones with label Good First Issue, but as during those events there are large number of contributors, one who comments on it first claims the issue. So, for claiming a Good First Issue one needs to constantly look for new issue and comment on it to claim it, which is really tiresome.

So, I came up with an idea to use web scraping libraries like Selenium to keep watch on any new Good First Issue and comment "Claim" on it.

I know how to look out for new issue with Good First Issue label on it. But I don't know how to tackle the main part of commenting on that issue.

Please help me come up with a solution of Watching out on a new Good First Issue and commenting on it to claim it. Is it possible to do it or I should leave the idea?

Edited code with commenting included but getting some errors.

from selenium import webdriver
from selenium.webdriver.common.by import By

website='https://github.com/ToolJet/ToolJet/issues?page=1&q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc'
path='C:\\Users\vedant\OneDrive\Desktop'
driver=webdriver.Chrome(path)

driver.get(website)

issue_labels = driver.find_elements(By.CLASS_NAME, "IssueLabel")

for issue_label in issue_labels:
    if issue_label.text == 'up-for-grabs':
        issue_parent_element = issue_label.find_element(By.XPATH, "..")
        issue_grandparent_element = issue_parent_element.find_element(By.XPATH, "..")
        issue_link_element = issue_grandparent_element.find_element(By.CLASS_NAME, "Link--primary")
        issue_link = issue_link_element.get_attribute('href')
        driver.get(issue_link)
        comment_box = driver.find_element(By.TAG_NAME, "textarea")
        comment_box.send_keys("Claiming this issue")
        submit_button = driver.find_element(By.XPATH, "//button[contains(text(),'Comment')]")
        submit_button.click()
        break

driver.close()
Traceback (most recent call last):
  File "C:\Users\vedant\PycharmProjects\HelloWorld\main.py", line 36, in <module>
    comment_box = driver.find_element(By.TAG_NAME, "textarea")
  File "C:\Users\vedant\PycharmProjects\HelloWorld\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 861, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "C:\Users\vedant\PycharmProjects\HelloWorld\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Users\vedant\PycharmProjects\HelloWorld\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"tag name","selector":"textarea"}
  • This isn't a code-writing service, but also this doesn't seem like a thing you should be writing as it only makes the problem worse. – jonrsharpe Feb 27 '23 at 20:25
  • Update the question with your code trials. – undetected Selenium Feb 27 '23 at 20:33
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 27 '23 at 21:31
  • 1
    Try to write code to do the following: (1) once you get the `href`, run `driver.get(href)` to load the issue page (2) using `driver.find_element` locate the form to enter the comment and click on it (3) write input with `send_keys` (4) press enter. Try this, then put here your code and ask if you have any problem – sound wave Mar 02 '23 at 16:40
  • @soundwave Sure I will try it and post the updated code – Vedant Borkar Mar 03 '23 at 15:48
  • `issue_link = issue_label.get_attribute('href')` is wrong, what you get is the label link not the issue link – sound wave Mar 05 '23 at 15:12
  • @soundwave I am able to successfully retrieve the link of issue with a particular tag(here for convenience I have used "up-for-grabs"). Driver is opening the issue page but after that it's not working. It says not able to find element with tagname textarea. I also tried to select the comment box textarea using XPath but it isn't working. Please suggest me any other way to to select the textarea. – Vedant Borkar Mar 06 '23 at 10:47

1 Answers1

1

NoSuchElementException may be due to the fact that the comment box is not fully loaded yet when you try to find it using find_element. To avoid this we can use WebDriverWait(driver, n) which try to find the element for n seconds.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = 'https://github.com/ToolJet/ToolJet/issues?page=1&q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc'
driver.get(url)

wait = WebDriverWait(driver, 9)

issue_xpath = "//a[contains(text(),'up-for-grabs')]/parent::span/preceding-sibling::a"
issue = wait.until(EC.element_to_be_clickable((By.XPATH, issue_xpath)))
print('Selected issue:', issue.text)
driver.get(issue.get_attribute('href'))

from selenium.webdriver.common.keys import Keys
comment_box = wait.until(EC.element_to_be_clickable((By.ID, "new_comment_field")))
comment_box.send_keys("Claiming this issue", Keys.CONTROL, Keys.RETURN)
sound wave
  • 3,191
  • 3
  • 11
  • 29
  • Thanks for the reply. The only hurdle is how should I keep GitHub signed in in webdriver. It needs to be signed in to comment. – Vedant Borkar Mar 07 '23 at 08:24
  • 1
    @VedantBorkar You can use cookies or an user profile, look here https://stackoverflow.com/a/75589648/8157304 – sound wave Mar 07 '23 at 08:27