Skip to main content

Posts

Download zip file returned from server in React

The app: I'm building an app that takes screenshots with puppeteer and returns them in a zip file to a react front end. Relevant technologies: node, react, express, puppeteer, AdmZip The issue: I can get the data to the point where it triggers the automatic download, but what gets downloaded does not appear to be a proper zip file as I get the following error when attempting to unzip: 'Unable to expand "screenshot-download.zip". Extra context: To ensure things were working as expected in the process of actually compressing the screenshots into a zip file, I also implemented the "writeZip" method to create a zip file straight from the server and onto my local file system (bypassing converting to buffer and sending to client). This zip file worked as expected and had all the correct contents. This is leading me to believe that the issue is somewhere in the process of sending to client and converting it to something usable. App.js code (front end): fe

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":XPATH}

A while back, I created this script that downloads a file from a website into a specified folder using Selenium. It's been working fine for the past couple months, but after updating the ChromeDriver to 111.0.5563.64 (March 20, 2023), the code is no longer working, producing an error on line 58: download_icon = driver.find_element(By.XPATH, dwnicon) The error says it can't locate the element (which I've asked for it to trace using XPATH) -- Traceback (most recent call last): File "c:\Users\ujcho\Desktop\Internal Weekly Bluesheet\HomicideReportCollector.py", line 58, in <module> download_icon = driver.find_element(By.XPATH, dwnicon) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ujcho\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 830, in find_element return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["val

Is there a really simple method for printing scraped output to a csv file?

Python: Python 3.11.2 Python Editor: PyCharm 2022.3.3 (Community Edition) - Build PC-223.8836.43 OS: Windows 11 Pro, 22H2, 22621.1413 Browser: Chrome 111.0.5563.65 (Official Build) (64-bit) I have a URL (e.g., https://dockets.justia.com/docket/puerto-rico/prdce/3:2023cv01127/175963 ) from which I'm scraping nine items. I'm looking to have the script create a csv file and write my scraped output (nine items) to columns in the csv file. Is there a really simple way of doing this? from bs4 import BeautifulSoup import requests import csv html_text = requests.get("https://dockets.justia.com/docket/puerto-rico/prdce/3:2023cv01127/175963").text soup = BeautifulSoup(html_text, "lxml") cases = soup.find_all("div", class_ = "wrapper jcard has-padding-30 blocks has-no-bottom-padding") for case in cases: case_title = case.find("div", class_ = "title-wrapper").text.replace(" "," ") case_plaintiff = c

PyCharm debug with "arch -x86_64 python3" command

I am looking for a way to debug my script in PyCharm using the "arch -x86_64 python3" command. The command is required to run a 64-bit version of Python (3.10.10) on my macOS system (M1 arm64) due to a library that is only available for x86_64 architecture. I am able to run my script in the PyCharm terminal with "arch -x86_64 python3 main.py", but how can I edit the debug configuration to debug it? Without the command, my script crashes as it launches Python in arm architecture mode. source https://stackoverflow.com/questions/75798892/pycharm-debug-with-arch-x86-64-python3-command

access cypress dataTable key and values

I am learning Cypress with BDD, I have little knowledge of it. I have data table like below: Scenario: Verify data table Given I can get values to corresponding keys | Key | Value | | Hello | World | | Foo | Bar | | John | Doe | I wrote a function to get values for corresponding keys. getDataTableValue(dataTable, keyValue){ let valueIs; dataTable.hashes().forEach((element) => { if (element.Key === 'Foo') { valueIs = element.Value; } }); return valueIs; } Now when I am calling this function, it always return top value i.e. "World" cy.log(getDataTableValue(dataTable, "Foo")); However when I run: dataTable.hashes().forEach((element) => { cy.log(element.Value); }); it wo

Why does shorthand if assignment to list not work?

Trying to use the code given below I get the error: row[0] = "M" if row[0] == "male" else row[0] = "F" ^^^^^^ SyntaxError: cannot assign to subscript here. Maybe you meant '==' instead of '='? rows = [] for row in csvreader: row[0] = "M" if row[0] == "male" else row[0] = "F" rows.append(row) However when I format it normally(see below) the error does not occur. Why is that? for row in csvreader: if row[0] == "male": row[0] = "M" else: row[0] = "F" rows.append(row) Note: row is list of strings Looking online at the error given it says it occurs because of an assignment to a literal, which doesn't seem to be the case. source https://stackoverflow.com/questions/75795262/why-does-shorthand-if-assignment-to-list-not-work

How to make search filter for each column in html table in react

I have a HTML table which I made from scratch and rendering it with APIs data, I did all the pagination sorting and other stuffs but now I am trying to do search filter for each column. I made one global search filter which works totally fine but facing issue with the making search for each column. What I am doing Below is my HTML table component <HTMLTable tableData={tData} // here passing data as tData tableClass="table" theadClass="theadClass" tbodyClass="tbodyClass" /> What I am doing is getting data from api and creating one state and updating it in useEffect when page loads as empty array dependency like below const [searchData, setsearchData] = useState(null); useEffect(() => { setsearchData(data); // here updating my state with the api data }, []); Now below is my logic I am using to filter the data const table_data = searchData && searchData.filter((it