Ok, so I have an error and I don't know why. I want to request a bunch of links from a file
while True:
code = file.readline().replace("\n", "")
r = request.get(code)
source = r.post(code)
print(source.text)
input()
Can someone please help me?
import requests at the beggining of the file
Related
I get the error message in the title when I start this script. How could I solve it? Python 3.7
I haven't updated any modules, it worked perfectly. Now, this error comes out.
AttributeError: 'CallbackContext' object has no attribute 'message'
Here is the code: pastebin
def post(bot, update):
print(url)
url = update.message.text.replace("/g ","")
print(url)
driver.get(url)
nameele = driver.find_element_by_xpath("//*[#class='sqdOP yWX7d _8A5w5 ZIAjV ']")
You're using depercated syntax for handler callbacks. Since v12.0, the signature of handler callbacks reads def callback(update: telegram.Update, context: telegram.ext.CallbackContext):. Please see the v12 transition guide for details.
Do you know repl.it?
I am coding python on this site.
And my goal is creating Web Scraper.
I think this code is clean.
But I'm getting an error:
AttributeError: 'function' object has no attribute 'text'
My code:
import requests
indeed_result = requests.get
("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
print(indeed_result.text)
Surely, I have requests package installed.
Please give me some advice
You just need to remove the back to new line after get like this:
import requests
indeed_result = requests.get("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
print(indeed_result.text)
if you want to continue typping in the next line just add a backslash \ as follows:
indeed_result = requests.get\
("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
Removing back to new line after get
try this
import requests
res = requests.get("https://kr.indeed.com/jobs?q=python&l=%EC%9D%B8%EC%B2%9C")
print(res.text)
# result if success 200
I am learning how to scrape web information. Below is a snippet of the actual code solution + output from datacamp.
On datacamp, this works perfectly fine, but when I try to run it on Spyder (my own macbook), it doesn't work...
This is because on datacamp, the URL has already been pre-loaded into a variable named 'response'.. however on Spyder, the URL needs to be defined again.
So, I first defined the response variable as response = requests.get('https://www.datacamp.com/courses/all') so that the code will point to datacamp's website..
My code looks like:
from scrapy.selector import Selector
import requests
response = requests.get('https://www.datacamp.com/courses/all')
this_url = response.url
this_title = response.xpath('/html/head/title/text()').extract_first()
print_url_title( this_url, this_title )
When I run this on Spyder, I got an error message
Traceback (most recent call last):
File "<ipython-input-30-6a8340fd3a71>", line 11, in <module>
this_title = response.xpath('/html/head/title/text()').extract_first()
AttributeError: 'Response' object has no attribute 'xpath'
Could someone please guide me? I would really like to know how to get this code working on Spyder.. thank you very much.
The value returned by requests.get('https://www.datacamp.com/courses/all') is a Response object, and this object has no attribute xpath, hence the error: AttributeError: 'Response' object has no attribute 'xpath'
I assume response from your tutorial source, probably has been assigned to another object (most likely the object returned by etree.HTML) and not the value returned by requests.get(url).
You can however do this:
from lxml import etree #import etree
response = requests.get('https://www.datacamp.com/courses/all') #get the Response object
tree = etree.HTML(response.text) #pass the page's source using the Response object
result = tree.xpath('/html/head/title/text()') #extract the value
print(response.url) #url
print(result) #findings
I am getting an Attribute error on line 8:browser.visit("https://www.facebook.com").
"AttributeError: 'NoneType' object has no attribute 'visit'"
This is my code:
browser = Browser('firefox')
browser.visit('https://www.facebook.com')
browser.find_by_id('email').fill("")
browser.find_by_id('pass').fill("")
browser.find_by_id('loginbutton').first.click()
browser.visit('')
while x != 0:
browser.find_by_css('textarea').fill('')
browser.find_by_id('u_0_1c').click()
It pulled up with a bunch of errors at first but I fixed those, I don't understand this error? If someone could maybe explain why or what is happening it would be much appreciated.
I think you need to have import the Browser package from splinter like this
from splinter import Browser
browser = Browser('firefox)
browser.visit('https://www.facebook.com')
I am trying to read image from url and save it to model. but i am getting this error message:
AttributeError: addinfourl instance has no attribute '__committed'
this is my code:
location = Location()
location.save()
image = urllib.urlopen(img_url)
location.locations_image.create(bild=image)
I guess, i am doing something wrong while reading an image file from url. can someone pls guide me? thanks a lot