Read first line of a raw text [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hey Im using my little scraper and I want to save results with one detail, first line of a raw pastebin/any other bin webpage.
lets say I have this code:
r=requests.get("https://pastebin.com/raw/qH03hKGU") #random link
text=r.text
I want to get the first line of the variable text without saving it (I will save just the one line)

You can use partition('\n')[0] to get the first line:
import requests
r=requests.get("https://pastebin.com/raw/qH03hKGU") #random link
text=r.text
print(text.partition('\n')[0])
OUT: import glob

Related

JSON Data mining with Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
I have the following problem. I have a JSON dataset where I would like to retrieve the data as follows: "id: XXXXXXX" wehere the x = numbers. The numbers are followed by "," and I just want to get the data up to that point. All datas what I mining want to save another txt file.
import json
f = open('data.json')
data = json.load(f)
I hope everthing is clear. :)
:)
I tried a few different possibility but I can not get solve my problem.

Python code will not compare from a text file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
This is a simplified version of my code for troubleshooting, its prints what it have to input in the comparison
this is the code running, it reads from the file but wont compare it to my input and gives the incorrect output
here is the text file
I just want the code to read from the file and have it compare to my input thank you :)
I've tried making the content of the file strings and variables for comparison but still the same result.

How to make a list of all Spanish words [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
All I need is to have a list (in Python) consisting of all words in Spanish. Once I have that, I will be running some scripts using this list, but building the list is proving to be more difficult than I expected. Thank you for any help.
Here's a raw list of spanish words I've found.
You can download the file and import them in python to put them into a list.
with open(spanish.txt) as file:
lines = file.readlines()
lines = [line.rstrip() for line in lines]

How to save variable into a file (like print but into file)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am asking how to save a text file in python, that can contain a variable.
I didn't tried anything because I am a beginner.
Let's say you have a file called file and it is a notepad (text/txt) document. Your code would go like this:
text = "This can be anything"
with open("file.txt", "w") as myfile:
myfile.write(text)
The tutorial on reading and writing files should help if you don't understand this. The w means that you can write to the file.

How to store Response in Scrapy? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to store response of the request in scrapy .i have the following code for the time being.
yield Request(requestURL,
callback=self.afterResponse)
Now what i want not to call the function afterResponse upon arrival of response but to store it here somehow so that i can extract the data of response at the same place.
Create some variable (it can be even list if you need to keep more data) in that spider and keep that data in it.
Or create/open some file and write it as pickle or something.

Categories

Resources