My script throws an error when I make a go using multiprocessing
I've created a script in python using multiprocessing library to scrape certain fields from a webpage. As I don't have any knowledge as to how I can make a go using multiprocessing I get an error when I execute the below script:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
if __name__ == '__main__':
links = [link.format(page) for page in range(4)]
p = Process(target=create_links, args=(links,))
p.start()
p.join()
Error I'm having:
722, in get_adapter
raise InvalidSchema("No connection adapters were found for '%s'" % url)
I'm getting that error because the script considers the list of links as an individual link whereas I knew I had to pass list of links within args=(links,). How may I run it successfully?
python python-3.x web-scraping multiprocessing
add a comment |
I've created a script in python using multiprocessing library to scrape certain fields from a webpage. As I don't have any knowledge as to how I can make a go using multiprocessing I get an error when I execute the below script:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
if __name__ == '__main__':
links = [link.format(page) for page in range(4)]
p = Process(target=create_links, args=(links,))
p.start()
p.join()
Error I'm having:
722, in get_adapter
raise InvalidSchema("No connection adapters were found for '%s'" % url)
I'm getting that error because the script considers the list of links as an individual link whereas I knew I had to pass list of links within args=(links,). How may I run it successfully?
python python-3.x web-scraping multiprocessing
stackoverflow.com/questions/39212867/…
– Naresh Kumar
Nov 16 '18 at 7:38
I've never been able to get good performance with python and threads, I imagine it depend partly on platform.
– pguardiario
Nov 16 '18 at 22:20
add a comment |
I've created a script in python using multiprocessing library to scrape certain fields from a webpage. As I don't have any knowledge as to how I can make a go using multiprocessing I get an error when I execute the below script:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
if __name__ == '__main__':
links = [link.format(page) for page in range(4)]
p = Process(target=create_links, args=(links,))
p.start()
p.join()
Error I'm having:
722, in get_adapter
raise InvalidSchema("No connection adapters were found for '%s'" % url)
I'm getting that error because the script considers the list of links as an individual link whereas I knew I had to pass list of links within args=(links,). How may I run it successfully?
python python-3.x web-scraping multiprocessing
I've created a script in python using multiprocessing library to scrape certain fields from a webpage. As I don't have any knowledge as to how I can make a go using multiprocessing I get an error when I execute the below script:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
if __name__ == '__main__':
links = [link.format(page) for page in range(4)]
p = Process(target=create_links, args=(links,))
p.start()
p.join()
Error I'm having:
722, in get_adapter
raise InvalidSchema("No connection adapters were found for '%s'" % url)
I'm getting that error because the script considers the list of links as an individual link whereas I knew I had to pass list of links within args=(links,). How may I run it successfully?
python python-3.x web-scraping multiprocessing
python python-3.x web-scraping multiprocessing
asked Nov 16 '18 at 7:35
robots.txtrobots.txt
268117
268117
stackoverflow.com/questions/39212867/…
– Naresh Kumar
Nov 16 '18 at 7:38
I've never been able to get good performance with python and threads, I imagine it depend partly on platform.
– pguardiario
Nov 16 '18 at 22:20
add a comment |
stackoverflow.com/questions/39212867/…
– Naresh Kumar
Nov 16 '18 at 7:38
I've never been able to get good performance with python and threads, I imagine it depend partly on platform.
– pguardiario
Nov 16 '18 at 22:20
stackoverflow.com/questions/39212867/…
– Naresh Kumar
Nov 16 '18 at 7:38
stackoverflow.com/questions/39212867/…
– Naresh Kumar
Nov 16 '18 at 7:38
I've never been able to get good performance with python and threads, I imagine it depend partly on platform.
– pguardiario
Nov 16 '18 at 22:20
I've never been able to get good performance with python and threads, I imagine it depend partly on platform.
– pguardiario
Nov 16 '18 at 22:20
add a comment |
3 Answers
3
active
oldest
votes
Works fine with Pool
import requests
from lxml.html import fromstring
from multiprocessing import Pool
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
links = [link.format(page) for page in range(4)]
def main():
with Pool(4) as p:
print(p.map(create_links, links))
if __name__ == '__main__':
main()
Output
Caffe Latte 6254 Wilshire Blvd (323) 936-5213
Bourgeois Pig 5931 Franklin Ave (323) 464-6008
Beard Papa Sweet Cafe 6801 Hollywood Blvd Ste 157 (323) 462-6100
Intelligentsia Coffee 3922 W Sunset Blvd (323) 663-6173
The Downbeat Cafe 1202 N Alvarado St (213) 483-3955
Sabor Y Cultura 5625 Hollywood Blvd (323) 466-0481
The Wood Cafe 12000 Washington Pl (310) 915-9663
Groundwork Coffee Inc 1501 N Cahuenga Blvd (323) 871-0143
The Apple Pan 10801 W Pico Blvd (310) 475-3585
Good Microbrew & Grill 3725 W Sunset Blvd (323) 660-3645
The Standard Hollywood 8300 W Sunset Blvd (323) 650-9090
Both of the solutions are working. I've got a question on yours' though. Ain't it necessary to use somewhere.join()command likep.join()or something?
– robots.txt
Nov 16 '18 at 8:14
No need to join anything.
– Richard Rublev
Nov 16 '18 at 8:15
Gonna accept your solution then. Thanks.
– robots.txt
Nov 16 '18 at 8:16
I am getting [None, None, None, None] when running this in Spyder. Is there something I may be missing?
– QHarr
Nov 16 '18 at 12:35
add a comment |
You can use Pool from multiprocessing
from multiprocessing import Pool
and specify processes as
links = [link.format(page) for page in range(4)]
p = Pool(10) # number of process at a time
link = p.map(parse, links)
p.terminate()
p.join()
It is working as well.
– robots.txt
Nov 16 '18 at 8:15
add a comment |
If you wanted to stick to Process then the following should work:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
try:
street = title.cssselect("span.street-address")[0].text
except IndexError: street = ""
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError: phone = ""
print(name, street, phone)
if __name__ == '__main__':
items =
for links in [link.format(page) for page in range(1,6)]:
p = Process(target=create_links, args=(links,))
items.append(p)
p.start()
for process in items:
process.join()
Finally worked out which environment I could run the above in. +
– QHarr
Nov 17 '18 at 11:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333341%2fmy-script-throws-an-error-when-i-make-a-go-using-multiprocessing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Works fine with Pool
import requests
from lxml.html import fromstring
from multiprocessing import Pool
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
links = [link.format(page) for page in range(4)]
def main():
with Pool(4) as p:
print(p.map(create_links, links))
if __name__ == '__main__':
main()
Output
Caffe Latte 6254 Wilshire Blvd (323) 936-5213
Bourgeois Pig 5931 Franklin Ave (323) 464-6008
Beard Papa Sweet Cafe 6801 Hollywood Blvd Ste 157 (323) 462-6100
Intelligentsia Coffee 3922 W Sunset Blvd (323) 663-6173
The Downbeat Cafe 1202 N Alvarado St (213) 483-3955
Sabor Y Cultura 5625 Hollywood Blvd (323) 466-0481
The Wood Cafe 12000 Washington Pl (310) 915-9663
Groundwork Coffee Inc 1501 N Cahuenga Blvd (323) 871-0143
The Apple Pan 10801 W Pico Blvd (310) 475-3585
Good Microbrew & Grill 3725 W Sunset Blvd (323) 660-3645
The Standard Hollywood 8300 W Sunset Blvd (323) 650-9090
Both of the solutions are working. I've got a question on yours' though. Ain't it necessary to use somewhere.join()command likep.join()or something?
– robots.txt
Nov 16 '18 at 8:14
No need to join anything.
– Richard Rublev
Nov 16 '18 at 8:15
Gonna accept your solution then. Thanks.
– robots.txt
Nov 16 '18 at 8:16
I am getting [None, None, None, None] when running this in Spyder. Is there something I may be missing?
– QHarr
Nov 16 '18 at 12:35
add a comment |
Works fine with Pool
import requests
from lxml.html import fromstring
from multiprocessing import Pool
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
links = [link.format(page) for page in range(4)]
def main():
with Pool(4) as p:
print(p.map(create_links, links))
if __name__ == '__main__':
main()
Output
Caffe Latte 6254 Wilshire Blvd (323) 936-5213
Bourgeois Pig 5931 Franklin Ave (323) 464-6008
Beard Papa Sweet Cafe 6801 Hollywood Blvd Ste 157 (323) 462-6100
Intelligentsia Coffee 3922 W Sunset Blvd (323) 663-6173
The Downbeat Cafe 1202 N Alvarado St (213) 483-3955
Sabor Y Cultura 5625 Hollywood Blvd (323) 466-0481
The Wood Cafe 12000 Washington Pl (310) 915-9663
Groundwork Coffee Inc 1501 N Cahuenga Blvd (323) 871-0143
The Apple Pan 10801 W Pico Blvd (310) 475-3585
Good Microbrew & Grill 3725 W Sunset Blvd (323) 660-3645
The Standard Hollywood 8300 W Sunset Blvd (323) 650-9090
Both of the solutions are working. I've got a question on yours' though. Ain't it necessary to use somewhere.join()command likep.join()or something?
– robots.txt
Nov 16 '18 at 8:14
No need to join anything.
– Richard Rublev
Nov 16 '18 at 8:15
Gonna accept your solution then. Thanks.
– robots.txt
Nov 16 '18 at 8:16
I am getting [None, None, None, None] when running this in Spyder. Is there something I may be missing?
– QHarr
Nov 16 '18 at 12:35
add a comment |
Works fine with Pool
import requests
from lxml.html import fromstring
from multiprocessing import Pool
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
links = [link.format(page) for page in range(4)]
def main():
with Pool(4) as p:
print(p.map(create_links, links))
if __name__ == '__main__':
main()
Output
Caffe Latte 6254 Wilshire Blvd (323) 936-5213
Bourgeois Pig 5931 Franklin Ave (323) 464-6008
Beard Papa Sweet Cafe 6801 Hollywood Blvd Ste 157 (323) 462-6100
Intelligentsia Coffee 3922 W Sunset Blvd (323) 663-6173
The Downbeat Cafe 1202 N Alvarado St (213) 483-3955
Sabor Y Cultura 5625 Hollywood Blvd (323) 466-0481
The Wood Cafe 12000 Washington Pl (310) 915-9663
Groundwork Coffee Inc 1501 N Cahuenga Blvd (323) 871-0143
The Apple Pan 10801 W Pico Blvd (310) 475-3585
Good Microbrew & Grill 3725 W Sunset Blvd (323) 660-3645
The Standard Hollywood 8300 W Sunset Blvd (323) 650-9090
Works fine with Pool
import requests
from lxml.html import fromstring
from multiprocessing import Pool
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
street = title.cssselect("span.street-address")[0].text
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError:
phone = ""
print(name, street, phone)
links = [link.format(page) for page in range(4)]
def main():
with Pool(4) as p:
print(p.map(create_links, links))
if __name__ == '__main__':
main()
Output
Caffe Latte 6254 Wilshire Blvd (323) 936-5213
Bourgeois Pig 5931 Franklin Ave (323) 464-6008
Beard Papa Sweet Cafe 6801 Hollywood Blvd Ste 157 (323) 462-6100
Intelligentsia Coffee 3922 W Sunset Blvd (323) 663-6173
The Downbeat Cafe 1202 N Alvarado St (213) 483-3955
Sabor Y Cultura 5625 Hollywood Blvd (323) 466-0481
The Wood Cafe 12000 Washington Pl (310) 915-9663
Groundwork Coffee Inc 1501 N Cahuenga Blvd (323) 871-0143
The Apple Pan 10801 W Pico Blvd (310) 475-3585
Good Microbrew & Grill 3725 W Sunset Blvd (323) 660-3645
The Standard Hollywood 8300 W Sunset Blvd (323) 650-9090
answered Nov 16 '18 at 7:53
Richard RublevRichard Rublev
1,96042138
1,96042138
Both of the solutions are working. I've got a question on yours' though. Ain't it necessary to use somewhere.join()command likep.join()or something?
– robots.txt
Nov 16 '18 at 8:14
No need to join anything.
– Richard Rublev
Nov 16 '18 at 8:15
Gonna accept your solution then. Thanks.
– robots.txt
Nov 16 '18 at 8:16
I am getting [None, None, None, None] when running this in Spyder. Is there something I may be missing?
– QHarr
Nov 16 '18 at 12:35
add a comment |
Both of the solutions are working. I've got a question on yours' though. Ain't it necessary to use somewhere.join()command likep.join()or something?
– robots.txt
Nov 16 '18 at 8:14
No need to join anything.
– Richard Rublev
Nov 16 '18 at 8:15
Gonna accept your solution then. Thanks.
– robots.txt
Nov 16 '18 at 8:16
I am getting [None, None, None, None] when running this in Spyder. Is there something I may be missing?
– QHarr
Nov 16 '18 at 12:35
Both of the solutions are working. I've got a question on yours' though. Ain't it necessary to use somewhere
.join() command like p.join() or something?– robots.txt
Nov 16 '18 at 8:14
Both of the solutions are working. I've got a question on yours' though. Ain't it necessary to use somewhere
.join() command like p.join() or something?– robots.txt
Nov 16 '18 at 8:14
No need to join anything.
– Richard Rublev
Nov 16 '18 at 8:15
No need to join anything.
– Richard Rublev
Nov 16 '18 at 8:15
Gonna accept your solution then. Thanks.
– robots.txt
Nov 16 '18 at 8:16
Gonna accept your solution then. Thanks.
– robots.txt
Nov 16 '18 at 8:16
I am getting [None, None, None, None] when running this in Spyder. Is there something I may be missing?
– QHarr
Nov 16 '18 at 12:35
I am getting [None, None, None, None] when running this in Spyder. Is there something I may be missing?
– QHarr
Nov 16 '18 at 12:35
add a comment |
You can use Pool from multiprocessing
from multiprocessing import Pool
and specify processes as
links = [link.format(page) for page in range(4)]
p = Pool(10) # number of process at a time
link = p.map(parse, links)
p.terminate()
p.join()
It is working as well.
– robots.txt
Nov 16 '18 at 8:15
add a comment |
You can use Pool from multiprocessing
from multiprocessing import Pool
and specify processes as
links = [link.format(page) for page in range(4)]
p = Pool(10) # number of process at a time
link = p.map(parse, links)
p.terminate()
p.join()
It is working as well.
– robots.txt
Nov 16 '18 at 8:15
add a comment |
You can use Pool from multiprocessing
from multiprocessing import Pool
and specify processes as
links = [link.format(page) for page in range(4)]
p = Pool(10) # number of process at a time
link = p.map(parse, links)
p.terminate()
p.join()
You can use Pool from multiprocessing
from multiprocessing import Pool
and specify processes as
links = [link.format(page) for page in range(4)]
p = Pool(10) # number of process at a time
link = p.map(parse, links)
p.terminate()
p.join()
answered Nov 16 '18 at 7:44
Naresh KumarNaresh Kumar
535416
535416
It is working as well.
– robots.txt
Nov 16 '18 at 8:15
add a comment |
It is working as well.
– robots.txt
Nov 16 '18 at 8:15
It is working as well.
– robots.txt
Nov 16 '18 at 8:15
It is working as well.
– robots.txt
Nov 16 '18 at 8:15
add a comment |
If you wanted to stick to Process then the following should work:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
try:
street = title.cssselect("span.street-address")[0].text
except IndexError: street = ""
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError: phone = ""
print(name, street, phone)
if __name__ == '__main__':
items =
for links in [link.format(page) for page in range(1,6)]:
p = Process(target=create_links, args=(links,))
items.append(p)
p.start()
for process in items:
process.join()
Finally worked out which environment I could run the above in. +
– QHarr
Nov 17 '18 at 11:23
add a comment |
If you wanted to stick to Process then the following should work:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
try:
street = title.cssselect("span.street-address")[0].text
except IndexError: street = ""
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError: phone = ""
print(name, street, phone)
if __name__ == '__main__':
items =
for links in [link.format(page) for page in range(1,6)]:
p = Process(target=create_links, args=(links,))
items.append(p)
p.start()
for process in items:
process.join()
Finally worked out which environment I could run the above in. +
– QHarr
Nov 17 '18 at 11:23
add a comment |
If you wanted to stick to Process then the following should work:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
try:
street = title.cssselect("span.street-address")[0].text
except IndexError: street = ""
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError: phone = ""
print(name, street, phone)
if __name__ == '__main__':
items =
for links in [link.format(page) for page in range(1,6)]:
p = Process(target=create_links, args=(links,))
items.append(p)
p.start()
for process in items:
process.join()
If you wanted to stick to Process then the following should work:
import requests
from lxml.html import fromstring
from multiprocessing import Process
link = "https://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA&page={}"
def create_links(url):
response = requests.get(url).text
tree = fromstring(response)
for title in tree.cssselect("div.info"):
name = title.cssselect("a.business-name span")[0].text
try:
street = title.cssselect("span.street-address")[0].text
except IndexError: street = ""
try:
phone = title.cssselect("div[class^=phones]")[0].text
except IndexError: phone = ""
print(name, street, phone)
if __name__ == '__main__':
items =
for links in [link.format(page) for page in range(1,6)]:
p = Process(target=create_links, args=(links,))
items.append(p)
p.start()
for process in items:
process.join()
answered Nov 16 '18 at 11:09
SIMSIM
10.8k31147
10.8k31147
Finally worked out which environment I could run the above in. +
– QHarr
Nov 17 '18 at 11:23
add a comment |
Finally worked out which environment I could run the above in. +
– QHarr
Nov 17 '18 at 11:23
Finally worked out which environment I could run the above in. +
– QHarr
Nov 17 '18 at 11:23
Finally worked out which environment I could run the above in. +
– QHarr
Nov 17 '18 at 11:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333341%2fmy-script-throws-an-error-when-i-make-a-go-using-multiprocessing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/questions/39212867/…
– Naresh Kumar
Nov 16 '18 at 7:38
I've never been able to get good performance with python and threads, I imagine it depend partly on platform.
– pguardiario
Nov 16 '18 at 22:20